Redux가 어려운 그대를 위한 튜토리얼 1
Redux 사용법 파헤쳐보기
Redux 패턴 요약
Slice 만들기 createSlice
const themeSlice = createSlice({
name: "theme",
initialState: DARK_THEME,
reducers: {
change: (state, action) => action.payload,
},
});
Store 생성 (configureStore)
const store = configureStore({
reducer: { theme: themeSlice.reducer },
});
Provider로 감싸기
<Provider store={store}>
<App />
</Provider>
useSelector로 상태 가져오기
const color = useSelector((state) => state.theme.color);
useDispatch로 상태 변경하기
const dispatch = useDispatch();
dispatch(themeSlice.actions.change(LIGHT_THEME));