This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useSWR from "swr"; | |
import "./App.css"; | |
function App() { | |
// Fetcher function | |
const fetcher = (...args) => fetch(...args).then((res) => res.json()); | |
// SWR implementation | |
const { data, error } = useSWR( | |
"https://jsonplaceholder.typicode.com/posts/1", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useLayoutEffect } from "react"; | |
import * as ReactDOM from "react-dom"; | |
function App() { | |
const [count, setCount] = useState(0); | |
const [flag, setFlag] = useState(false); | |
function handleClick() { | |
console.log("=== click ==="); | |
fetchSomething().then(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "./App.css"; | |
import Home from "./Home"; | |
function App() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<Home /> | |
</header> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Amplify from "aws-amplify"; | |
import awsExports from "./aws-exports"; | |
import { AmplifySignOut, withAuthenticator } from "@aws-amplify/ui-react"; | |
Amplify.configure(awsExports); | |
const Home = (props) => { | |
return ( | |
<div> | |
<AmplifySignOut /> | |
<h1>This is your logged in page.</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useAxios from './useAxios'; | |
const App = () => { | |
const { response, error, loading } = useAxios({ | |
method: 'POST', | |
url: '/posts', | |
headers: { | |
accept: '*/*', | |
}, | |
data: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
const useAxios = (params) => { | |
const [response, setResponse] = useState(null); | |
const [error, setError] = useState(null); | |
const [loading, setLoading] = useState(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import useAxios from './useAxios'; | |
const App = () => { | |
const { response, error, loading } = useAxios(); | |
return ( | |
<div className="app"> | |
{loading ? ( | |
<div>Loading...</div> | |
) : ( | |
<div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
const useAxios = () => { | |
const [response, setResponse] = useState(null); | |
const [error, setError] = useState(null); | |
const [loading, setLoading] = useState(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from 'react'; | |
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
const App = () => { | |
const [response, setResponse] = useState(null); | |
const [error, setError] = useState(null); | |
const [loading, setLoading] = useState(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
import axios from 'axios'; | |
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com'; | |
const App = () => { | |
const fetchData = async () => { | |
try { | |
const res = await axios.get('/posts'); | |
console.log(res.data); |
NewerOlder