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>
);
}