javascript Redux容器样板#redux

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Redux容器样板#redux相关的知识,希望对你有一定的参考价值。

import React, { Component } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { fetchWeather } from "../actions/index"; //action

//Component becoming a container for redux
class SearchBar extends Component {

    constructor(props) {
        super(props);

        this.state = { term: '' };

        this.onInputChange = this.onInputChange.bind(this);
        this.onFormSubmit = this.onFormSubmit.bind(this);
    }

    componentDidMount() {
        console.log(`${this.constructor.name} component mounted...`);
    }

    onInputChange(event) {
      
    }

    onFormSubmit(event) {
        event.preventDefault();
    }

    render() {
        return (
          <div>your component here...</div>
        );
    }
}

function mapDispatchToProps(dispatch) {
    //return bindActionCreators({ fetchWeather }, dispatch); //action, dispatch
}
function mapStateToProps({weather}) {
    return { weather };
}


export default connect(null, mapDispatchToProps)(SearchBar);

以上是关于javascript Redux容器样板#redux的主要内容,如果未能解决你的问题,请参考以下文章

将 props 传递给 react-redux 容器组件

减少 redux-thunk 样板

React Redux Falcor 和 RethinkDB 样板

更新 Redux 状态,然后在同一实例中获取更新后的状态

javascript React Redux容器组件

在 redux 中使用样板动作和 reducer