Skip to content

Instantly share code, notes, and snippets.

@anhtuank7c
Last active January 7, 2017 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhtuank7c/42819438acb7a3c6b48d783e0f5462de to your computer and use it in GitHub Desktop.
Save anhtuank7c/42819438acb7a3c6b48d783e0f5462de to your computer and use it in GitHub Desktop.
Reducer example
import {
TIME_CHANGE
} from '../actions/types';
// khai báo 1 trạng thái khởi
const INITIAL = {
hour: 0
};
// reducer này sẽ nhận trạng thái khởi tạo ở bên trên nếu như state chưa
export default (state = INITIAL, action) => {
switch(action.type) {
case TIME_CHANGE:
// nếu sự kiện TIME_CHANGE được gọi (action thay đổi time)
// merge state hiện hành và cập nhật hour bằng giá trị truyền từ action.
return {...state, hour: action.payload};
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment