

//App.js
//data를 내보내는 context
export const DiaryStateContext = React.createContext();
//data의 상태를 변화시키는 함수를 내보내는 context
export const DiaryDispatchContext = React.createContext();
return(
<DiaryStateContext.Provider value={data}>
<DiaryDispatchContext.Provider value={memoizedDispatches}>
<div className="App">
<DiaryEditor/>
<div>전체 일기 : {data.length}</div>
<div>기분 좋은 일기 개수 : {goodCount}</div>
<div>기분 나쁜 일기 개수 : {badCount}</div>
<div>기분 좋은 일기 비율 : {goodRatio}</div>
<DiaryList />
</div>
</DiaryDispatchContext.Provider>
</DiaryStateContext.Provider>
)
Provider로 컴포넌트들을 감싸준다
props는 필요 없다.
//DiaryItem.js
const {onCreate} = useContext(DiaryDispatchContext)
//DiaryList.js
const diaryList = useContext(DiaryStateContext);
//DiaryItem.js
const {onRemove, onEdit} = useContext(DiaryDispatchContext);
이건 다시 복습해보기