RN(React-Native) 시작하기 7 - Redux 사용하기

kwlee·2021년 8월 10일
0

RN(React-Native)

목록 보기
7/9

Redux 설치

npm install redux react-redux --save

axios 설치

npm install axios

redux-thunk 설치

npm install redux-thunk

action-type, action, reducer 생성

// Action Types
const SET_INITIAL = 'camp/SET_INITIAL';

// Actions
export const getCampList ...

// Reducers
export default function (state: { [key: string]: any } = initialState, action: any) {
  switch (action.type) {
    case SET_INITIAL:
      return initialState;
    default:
      return state;
  }
}

루트 컴포넌트에 Provider store 연결

import { Provider } from 'react-redux';
import { createStore } from 'redux';
import rootReducer from '~/store';
import ReduxThunk from 'redux-thunk';
...
...
...

function App() {
  const store = createStore(rootReducer, applyMiddleware(ReduxThunk))
  
  return (
    <Provider store={store}>
      ...
    </Provider>
  );
}
profile
안녕하세요.

0개의 댓글