美文网首页
react-redux简单使用

react-redux简单使用

作者: 易路先登 | 来源:发表于2020-04-04 19:24 被阅读0次
  • 第一个重要api
    Provider将组建与store连接
import { Provider } from "react-redux";
import store from "./store/index.js";
import App from './App';

ReactDOM.render(
  <Provider store = {store}>
    <App />
  </Provider>,
  document.getElementById('root')
);
  • 第二个重要api
    connect将具体组建与store数据建立对应映射
export default connect(fun1,fun2)(***Component)

fun1是将仓库数据映射到组件props的函数

mapStoreStateToProps(storeState){
    return {
          ***:storeState.xxx
    }
}

fun2是将仓库的dispatch映射到组件的函数

mapDispatchToProps(dispatch){
    return{
        xxxxx(params){
            const action = {
                type:***
            }
            dispatch(action);
        }
    }
}

学会这两个api就能使用react-redux了,需要注意的是,react-redux依赖的redux,使用前需要安装redux,它不能独立工作。

相关文章

  • react-redux

    使用react-redux,可以更方便的使用redux开发 先install react-redux使用react...

  • react-redux简单使用

    第一个重要apiProvider将组建与store连接 第二个重要apiconnect将具体组建与store数据建...

  • Redux使用(纯Redux使用)

    会简单介绍Redux,然后使用纯Redux (不是使用react-redux) 写一个例子 目前使用版本 Redu...

  • react-redux

    一、作用 react-redux插件可以使redux的使用变得更加简单。 二、使用 首先,要创建store和red...

  • Provider高阶组件

    Provider provider是react-redux提供的一个高阶组件 使用Provider的简单步骤: 创...

  • 20.redux使用

    react-redux 使用一个react-redux 的库使得redux的使用更简洁,它提供了provider和...

  • 【React进阶系列】手写实现react-redux api

    简介:简单实现react-redux基础api react-redux api回顾 把store放在context...

  • react-redux的简单使用

    正式接触react应该有两个月了,项目开始也有一个月了,开始新项目的时候就没有打算使用redux,因为感觉学习这个...

  • react-redux

    redux 全局状态管理 react-redux 优化模块 优化redux的使用过程 通过react-redux ...

  • React-Redux(一):react-redux使用

    react-redux使用步骤如下添加react-redux库 2.创建store 在祖先元素引入provider...

网友评论

      本文标题:react-redux简单使用

      本文链接:https://www.haomeiwen.com/subject/cyajphtx.html