Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 동전 0
- 로딩 후 실행
- NextJS v13
- 서버 컴포넌트
- 백준
- 배열 중복 제거
- 프로그래머스
- react
- JavaScript
- 그리디
- 알고리즘
- 부트캠프항해
- server component
- 중복카테고리
- 클라이언트 컴포넌트
- 항해99추천
- 실전프로젝트
- 항해99
- greedy
- 항해99후기
- 탐욕알고리즘
- 숫자를 별점으로
- 날씨 api
- 중복선택
- db수정
- 카테고리필터
- 항해99솔직후기
- 자바스크립트
- jQuery
- 배열 메소드
Archives
- Today
- Total
공부 및 일상기록
[React] redux 설정하기 본문
1. 리덕스 설정
vscode터미널에 아래 명령어를 입력
yarn add redux react-redux
(redex와 react-redux를 동시설치하는 명령어)
2. 폴더구조 생성하기
src 폴더 안에 redux 폴더 생성
redux 폴더 안에 config, modules 폴더 생성
config폴더 안에 concfigStore.js 파일 생성
폴더설명
redux : 리덕스와 관련된 코드를 모두 모아 놓을 폴더
config : 리덕스 설정과 관련된 파일들을 놓을 폴더
configStore : "중앙 state 관리소" 인 store를 만드는 설정 코드들이 있는 파일
modules : 우리가 만들 state들의 그룹
3. 설정 코드 작성
configStore.js 에 아래 코드 삽입
import { createStore } from "redux";
import { combineReducers } from "redux";
const rootReducer = combineReducers({});
const store = createStore(rootReducer);
export default store;
index.js 에 아래 코드 삽입
// 원래부터 있던 코드
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
// 우리가 추가할 코드
import store from "./redux/config/configStore";
import { Provider } from "react-redux";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
//App을 Provider로 감싸주고, configStore에서 export default 한 store를 넣어줍니다.
<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();
리액트에서 리덕스를 사용하려면 redux와 react-redux가 필요하다.
설정코드는 지금 당장 이해 할 필요가 없다.
configStore.js 를 Store라고 부른다.
모듈이란 state들의 그룹이다.
'개발 > React' 카테고리의 다른 글
[React] 옵셔널 체이닝 이란 무엇일까? (1) | 2022.10.11 |
---|---|
[React] 리덕스 (redux) 아주 간단한 흐름 (1) | 2022.10.11 |
[React] redux(toolkit) 설정하기 (0) | 2022.10.08 |
[React] styled-componets 준비 (0) | 2022.10.07 |
[React] TodoList 만들기 (1) | 2022.10.04 |