flatwhite01 님의 블로그
redux 본문

import { createSlice } from '@reduxjs/toolkit';
//자바스크립트 영역 toolkit 내부에 지원해준다
const initialState = {
count: 0,
};
export const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment: (state, action) => {
// action.payload => UI 디자인에서 값을 넘긴것을 받기
//state.키 =>initialState 에 초기변수 연결
state.count += 1;
},
decrement: (state, action) => {
state.count -= 1;
},
onReset: (state, action) => {
state.count = 0;
},
},
});
// Action creators are generated for each case reducer function
export const { increment, decrement, onReset } = counterSlice.actions;
export default counterSlice.reducer;
저장소(store)에서 toolkit 이미 만들어진 것에서 함수를 만든다!

여기서 연결을 한다
저장소(store) ->App 내려주고 state 매개변수 내려받는다

'react' 카테고리의 다른 글
| redux 정리 (0) | 2025.03.05 |
|---|---|
| React와 Next.js의 차이 (0) | 2025.01.07 |
| [React] 설치 방법 (2) | 2025.01.07 |
| vercel 배포 방법 (1) | 2025.01.06 |