[KDT]FCFE - 10주1일 Redux Review

Keunyeong Lee·2022년 1월 24일
0
post-thumbnail

Redux

Redux 복습

npm i react-redux 설치

npm i @reduxjs/toolkit 설치

  • name-slice.js

createSlice() 생성

initialState 생성

const uiAcitons = uiSlice.actions; 생성

  • src/store/index.js

const store = configureStore({ reducer: { ui: uiSlice.reducer } });

  • src/index/js
    : react-redux Provider로 store 연결해주기
<Provider store={store}><App/></Provider>
  • 사용할 component

: react-redux 의 useDispatch 사용

: dispatch(uiActions.toggle()) 과 같이 actions 사용.

uiActions.toggle() 인자로 그냥 넣으면 payload 로 들어감.

인자로 객체를 전달할 수 있다.

  • store 데이터를 사용할 component

useSelector(state=> state.ui.cartIsVisable)

state 데이터 사용.

profile
🏃🏽 동적인 개발자

0개의 댓글