Notice
Recent Posts
Recent Comments
Link
«   2026/05   »
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 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

flatwhite01 님의 블로그

redux 본문

react

redux

flatwhite01 2025. 1. 15. 10:49

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