React - Redux Toolkit 설치법

thisishwarang·2023년 1월 3일
0

Redux는 props없이 state를 공유할 수 있게 도와주는 라이브러리이다.
js파일 하나에 모든 state들을 보관해서 모든 컴포넌트들이 state를 꺼내 쓸 수 있다.
(규모가 작은 프로젝트에선 props를 쓰는게 코드가 짧겠지만 컴포넌트가 많아질 수록 더 효율적!)

설치법

npm install @reduxjs/toolkit react-redux
(react, react-dom dl 18.1.x 이상 버전이어야한다)

src에 store.js파일 만들고

import { configureStore } from '@reduxjs/toolkit'
 
export default configureStore({
	reducer: {
    
    	}
    })

index.js 파일에서

import { Provider } from 'react-redux'
import store from './store'

<Provider store={store}>
	<BrowserRouter>
    	<App/>
    </BrowserRouter>
</Provider>

이러면 설치는 완료
사용법은 다음에

출처 : https://codingapple.com/

0개의 댓글