Rematch
import { init, RematchDispatch, RematchRootState } from '@rematch/core';
import selectPlugin from '@rematch/select';
import persistPlugin from '@rematch/persist';
import sessionStorage from 'redux-persist/lib/storage/session';
import models from './models';
const persistConfig = {
key: 'root',
storage: sessionStorage,
whitelist: []
};
const store = init({
models,
plugins: [
selectPlugin(),
persistPlugin(persistConfig)
],
});
export const { select } = store;
export default store;
store
export default {
common: {
state,
reducers: {
setData(state, payload) {
retrun {..state, ...payload}
}
},
effects: dispatch => ({
init (payload) {
}
})
effects: {
init(payload, rootState) {}
}
}
存取
import { useDispatch, useSelector } from 'react-redux';
const dispatch = useDispatch();
const common = useSelector(state => state.common);
dispatch.common.init();