rematch简单使用

rematch简单使用import init dispatch from rematch core constcount state number 0 reducers 一个改变该 modelstate 的所有函数的对象 increments state payload gt state number payload decrements stat

import {init,dispatch} from ‘rematch/core’;

 

const count = {

state:{

number:0

},

reducers:{//一个改变该model state的所有函数的对象

increments:(state,payload) => state.number + payload,

decrements:(state,payload) => state.number – payload,

},

effects:{//方法都写在这里

async asyncIncrements(payload){//异步增加

await this.increments(payload);

},

async asyncDecrements(payload){

await this.decrements(payload);

}

 

}

}

 

const store = init({

models:{count},

redux:{}

})

 

dispatch.count.asyncIncrements(10);//异步增加10

dispatch.count.asyncDecrements(10);//异步减少10

使用:

import React from ‘react’

import {connect} from ‘react-redux’

 

class App extends Component{

addCount = (value)=>{//异步增加数据

const { CountDispatch } = this.props;

CountDispatch.asyncIncrements(value);

}

 

cutCount = (value) =>{//异步减少数据

const {CountDispatch} = this.props;

CountDispatch.asyncIncrements(value);

}

 

render(){

let {CountNumbers} = this.props;

return (

获取count数据中的number变化:{CountNumbers.number}

)

}

}

const mapStateToProps =(state)=>{

CountNumbers:state.count,//获取count数据

}

const mapDispatchToProps=(dispatch)=>{

CountDispatch:dispatch.count,//获取count方法

}

 

export default connect(mapStateToProps,mapDispatchToProps)(App)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/198542.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月26日 下午2:58
下一篇 2026年3月26日 下午2:59


相关推荐

  • Python 如何理解又晕又好用的装饰器

    Python 如何理解又晕又好用的装饰器

    2021年9月17日
    42
  • 一文搞懂深度学习正则化的L2范数

    一文搞懂深度学习正则化的L2范数想要彻底弄明白 L2 范数 必须要有一定的矩阵论知识 L2 范数涉及了很多的矩阵变换 在我们进行数学公式的推到之前 我们先对 L2 范数有一个感性的认识 L2 范数是什么 L2 范数的定义其实是一个数学概念 其定义如下 这个公式看着相当熟悉吧 用的最多的欧式距离就是一种 L2 范数 表示向量元素的平方和再开方 正则化中的 L2 范数说到正则化 我们要看一下 正则化在深度学习中含义是指什么

    2026年3月20日
    1
  • DDl,DML语句

    DDl,DML语句1 数据库 1 概述数据库 DataBase DB 指长期保存在计算机的存储设备上 按照一定规则组织起来 可以被各种用户或应用共享的数据集合 数据库管理系统 DataBaseMana DBMS 指一种操作和管理数据库的大型软件 用于建立 使用和维护数据库 对数据库进行统一管理和控制 以保证数据库的安全性和完整性 用户通过数据库管理系统访问数据库中的数据 数

    2026年3月26日
    2
  • classcastingexception_c++链接错误

    classcastingexception_c++链接错误转载自:http://www.blogjava.net/Sunday/archive/2007/08/18/137860.html现在java编程中经常碰到ClassCastException错误,ClassCastException是JVM在检测到两个类型间的转换不兼容时引发的运行时异常。此类错误通常会终止用户请求。本模式试图为您提供了解和排除ClassCastExcept

    2025年10月15日
    5
  • ajax 写法_常见词缀汇总

    ajax 写法_常见词缀汇总title:Ajax写法date:2018-06-3011:01:47tags:Ajax写法作者:李忠林Github: https://github.com/LeezhonglinGitblog:https://leezhonglin.github.io/什么是AJAX?AJAX=AsynchronousJavaScriptandXML(异步的JavaScript和…

    2022年9月30日
    5
  • 如何安装Java?

    如何安装Java?在本文中,我们将研究如何安装Java,在Windows操作系统中安装Java,如何检查已安装的版本以及设置环境变量。因此,让我们开始吧。如何安装Java?Java支持许多平台,例如Windows,Linux,Solaris等。这些平台具有自己的安装方法。在本教程中,我们将介绍32位和64位OS的安装过程Windows操作系统。Windows操作系统中的Java安装在Windows操作系统中,32位和64位Windows操作系统都具有类似的Java安装方式。主要区别在于它们的安装软件包。如何检查主机

    2022年7月9日
    24

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号