■ Redux
리덕스는 가장 사용률이 높은 상태관리 라이브러리로써 리액트의 복잡한 컴포넌트 구조속에서 보다 간편하게 모든 컴포넌트들이 state 를 쉽게 공유할 수 있게 해주는 방식
import { createStore } from 'redux';
많은 리듀서들을 합쳐서 하나의 reducer로 관리할 수 있게 한다.
import {combineReducers} from 'redux',
(...)
const todoApp = combineReducers({visibilityfilter, todos});
최상위의 index.js 파일 내에서 스토어를 만들어 줄 수 있다.
import {createStore} from 'redux';
import reducers from './modules';
//리듀서들을 store 안에 넣어서 서로 연결해준다.
const store = createStore(reducers, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
(...)
//이후 render함수 아래에 전달해준다.
<Provider store={store}>
스토의 내의 상태를 가져와준다.
console.log(store.getState());
디스패치는 스토어의 내장 함수 중 하나로 리듀서에게 Action을 전달한다. dispatch 함수는 dispatch(action) 이런 식으로 Action 을 인자로 넘긴다.