Practice
以下的code大部份來自 Mastering React Native(書)
creating the store
只有一個reducer的時候
import { createStore } from 'redux';
const initialState = {
count: 0
};
const countReducer = (state = initialState, action) => {
switch (action.type) {
case 'INCREMENT':
return {
count: state.count + 1
};
case 'DECREMENT':
return {
count: state.count - 1
};
case 'ZERO':
return {
count: 0
};
default:
return state;
}
}
export default createStore(countReducer); 多個reducer
入口
Action creators
action.js
要使用action的component => index.js
React context and providers
Middleware
參考
Last updated
