npm i redux
npm i next-redux-wrapper
store폴더를 생성 후, configureStore.js 파일을 생성해준다.
기본셋팅
configureStore.js
import { createWrapper } from 'next-redux-wrapper';
import { createStore } from 'redux';
const configureStore = () => {
const store = createStore(reducer);
return store;
}
const wrapper = createWrapper(configureStore, {
debug: process.env.NODE_ENV === 'development'
});
export default wrapper;
_app.js
import wrapper from '../store/configureStore';
export default wrapper.withRedux(NodeBird);
next에서는 Provider로 감싸주지않아도된다. 오히려 감싸면 문제가 생긴다.
여러 컴포넌트에서 공통으로 쓰이는 데이터들을 중앙에서 만들어서 관리를 해주는데 redex다.(react에서는 Context API)
redux(중앙저장소)를 쓰면 에러가 날 일이 별로 없다.
대신 코드양이 엄청나게 많다.