Last active
January 7, 2017 16:10
-
-
Save anhtuank7c/42819438acb7a3c6b48d783e0f5462de to your computer and use it in GitHub Desktop.
Reducer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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