Rematch
typescript
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)
],
});
// store 初始化
export const { select } = store;
export default store;
store
typescript
export default {
common: {
state,
reducers: {
setData(state, payload) {
retrun {..state, ...payload}
}
},
effects: dispatch => ({
init (payload) {
}
})
// or rootState
effects: {
init(payload, rootState) {}
}
}
存取
typescript
import { useDispatch, useSelector } from 'react-redux';
const dispatch = useDispatch();
const common = useSelector(state => state.common);
dispatch.common.init();