우주먼지 개발 log
[TIL] 23/11/09 React 숙련: Redux 란? 본문
반응형
한 일
- redux 강의 다 듣기
- 알고리즘 스터디 : 프로그래머스 4문제 풀기
TIL
Redux ?
전역 상태(Global state) 관리 라이브러리
기존 useState 불편 해소
- 컴포넌트 간에 상태(state)를 공유 하려면 부모자식 관계여야 하고,
조부모와 손자 사이에 낀 부모 컴포넌트들은 props 를 사용하지 않아도 전달해야 함.
중앙 state 관리소에서 Global state를 생성하고 관리하면
컴포넌트들은 어디서든지 state를 불러와 사용할 수 있다.
Redux 설치
yarn add redux react-redux
폴더구조
src/redux : 리덕스 관련 코드 모음
src/redux/config : 리덕스 설정 파일 모음
src/redux/config/configStore.js : 중앙 state 관리소! store를 만드는 설정코드들
src/redux /modules : 만들 State들의 파일 모음
(src/redux /modules/todo.js : 내가만든 todo 파일)
//src/configStore.js
import { createStore } from "redux";
import { combineReducers } from "redux";
const rootReducer = combineReducers({
todos,
}); // 여러 독립적인 reducer의 반환값들을 하나의 상태 객체로 만듬
const store = createStore(rootReducer); //store를 만든다
//createStore는 권장하지 않음 -> 요새는 configureStore를 쓴다!!
export default store;
//index.js
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
// 추가한 코드 (store와 Provider) : START
import store from "./redux/config/configStore";
import { Provider } from "react-redux";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
//App을 Provider로 감싸주고, configStore에서 export 한 store를 넣어줌
<Provider store={store}>
<App />
</Provider>
);
// 추가한 코드 : END
// 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를 Redux-Tool-Kit 으로 리팩토링 해보자~~
[TIL] 23/11/29 React 심화: Redux를 Redux Toolkit 으로 리팩토링
오늘도 화이팅! TIL 일반 redux 를 redux-toolkit 으로 리팩토링 보통 현업에서 일반 리덕스는 쓸일은 없다고 한다~ 어제 설치만 적어놓은 글에 리팩토링 방법을 왕창 추가하였다. 이제 과제에 적용만
developer.happymunzi.com
할 일 / 부족한 점
- 프로그래머스 문제 풀이 깃 허브 올리고 제출하기
반응형
'TIL(Today I Learned) > 스파르타 내배캠' 카테고리의 다른 글
[TIL] 23/11/13 React 숙련: React 개념정리, 개인과제 ing (0) | 2023.11.14 |
---|---|
[TIL] 23/11/10 React 숙련: 부분 렌더링 연습 (0) | 2023.11.13 |
[TIL] 23/11/08 React 숙련: useState 함수전달 (0) | 2023.11.08 |
[TIL] 23/11/07 React 입문: 이벤트 핸들러( feat. 매개변수) (0) | 2023.11.08 |
[TIL] 23/11/06 React 입문: 개인과제 TodoList (0) | 2023.11.07 |