React store Rematch

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();
相关推荐
parade岁月5 分钟前
理解 CSS backface-visibility:卡片翻转效果背后的属性
前端·css
用户47949283569155 分钟前
为什么 react-grab 可以在 Vue 项目中使用?
前端·ai编程
w***42416 分钟前
SpringSecurity的配置
android·前端·后端
yugi98783823 分钟前
TDOA算法MATLAB实现:到达时间差定位
前端·算法·matlab
锂享生活24 分钟前
金句闪卡生成器
前端·javascript·react.js
s***353027 分钟前
SpringMVC新版本踩坑[已解决]
android·前端·后端
涔溪35 分钟前
深入了解 Vite 的核心特性 —— 开发服务器(Dev Server)和热更新(HMR)的底层工作机制
前端·vite
前端一课1 小时前
【vue高频面试题】第 14 题:Vue3 中虚拟 DOM 是什么?为什么要用?如何提升性能?
前端·面试
前端一课1 小时前
【vue高频面试题】第 17 题:Vue3 虚拟 DOM 与 PatchFlag 原理 + 静态节点提升
前端·面试
前端一课1 小时前
【vue高频面试题】第 13 题:Vue 的 `nextTick` 原理是什么?为什么需要它?
前端·面试