본문 바로가기
Programming/Javascript

React강좌3 - Redux2. Action작성

by Wilkyway 2020. 8. 8.
반응형

1. 값 증가 액션

2. 값 감소 액션

3. 색 변경 액션

 

SRC/Actions폴더에 아래 2개의 파일 생성

 

1. ActionTypes.js

export const INCREMENT = "INCREMENT";
export const DECREMENT = "DECREMENT";
export const SET_COLOR = "SET_COLOR";

2. index.js

// 액션 생성자

//import { INCREMENT, DECREMENT, SET_COLOR } from './ActionTypes';
import * as types from './ActionTypes'; //위 구문과 동일한 의미

export function increment() {
    return {
        type: types.INCREMENT
    };
}

export function decrement() {
    return {
        type: types.DECREMENT
    };
}

export function setColor(color) {
    return {
        type: types.SET_COLOR,
        color
    };
}
반응형

댓글