Redux 셋업

이시원·2022년 9월 14일
0

Redux 공부

목록 보기
2/12
post-thumbnail


npm install redux
npm install react-redux
// index.js
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { Provider } from "react-redux";
import store from "./redux/store";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  // App.js에 store를 제공해주기 위해 Provider로 감쌈
  <Provider store={store}>
    <App />
  </Provider>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

// reducer.js
// state 초기화
let initialState = {
  count: 0,
};

function reducer(state = initialState, action) {}

export default reducer;
// store.js
import { createStore } from "redux";
import reducer from "./reducer/reducer";

let store = createStore(reducer);

export default store;
profile
코딩공부

0개의 댓글