191126 TIL 코쿼 과제 - useEffect
Nov 26, 2019
»
1.5막,
TIL (Today I Learned),
코드스쿼드,
React.js
import React, { useEffect, useState } from "react";
import { usePressStateCtx, usePressDispatchCtx } from "../PressContext";
const PressContent = () => {
const [data, setData] = useState("");
const [companyList, setCompanyList] = useState("");
const state = usePressStateCtx();
useEffect(() => {
setData(state.data);
}, []);
useEffect(() => {
let arr = [];
if (data) {
data.forEach(press => {
arr.push({
name: press.company,
id: press.id,
img: press.logoImgUrl
})
});
}
if (arr.length > 0) setCompanyList(arr);
}, [data]);
useEffect(() => {
console.log('왜 여기는 안 찍히는가..',companyList)
},[companyList]);
return companyList && <h1>된다.</h1>
};
export default PressContent;