只使用 reducer

用法跟redux一模一样。

import { createStore, combineReducers } from 'redux-mutation';

function counter(state = 0,action){
  switch(action.type){
    case "increase"
      return state + 1
    default: 
      return state;
  }
}
const reducer = combineReducers({ counter });
const store = createStore(reducer);
store.subscribe(function() {
  console.log('rendered', 'You can render dom here.');
});
store.dispatch({ type: 'increase' });

Last updated

Was this helpful?