const Page1 = ({history, props}) => {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(()=>{
axios("https://fangmin26.github.io/data/personal.json")
.then((res)=>{
setData(res.data)
})
.catch((err)=>{
console.error("fetch error",err);
setError(err)
})
.finally(()=>{
//setLoading(false)
setTimeout(function(){
setLoading(false);
},3000)
})
},[])
if(error) return "error";
if(loading) return <Loading/>;
return (
'프론트엔드 공부 > react' 카테고리의 다른 글
Contextapi 함수형, 상태값과 변수전달 (0) | 2021.07.27 |
---|---|
contextapi 예제 (0) | 2021.07.26 |
useState,useEffect 로 parrallex구현 (0) | 2021.07.14 |
chart.js활용하여 chart 만들기 (0) | 2021.07.11 |
axios 활용하여 JSON.stringify로 데이터 가져오기 (0) | 2021.07.11 |