Javascript 从react redux接收数据

Javascript 从react redux接收数据,javascript,reactjs,Javascript,Reactjs,我收到的数据有问题 我使用axios创建动作,并且知道它运行良好,承诺状态为200并获得 然后,我希望在容器fetch\u用户上的按钮onClick上使用初始函数HandleClick,因此我创建了新的容器: class FetchUsers extends Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); } handleCl

我收到的数据有问题

我使用axios创建动作,并且知道它运行良好,承诺状态为200并获得

然后,我希望在容器fetch\u用户上的按钮onClick上使用初始函数HandleClick,因此我创建了新的容器:

class FetchUsers extends Component {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(e) {

    e.preventDefault();
    console.log('thisporps', this.props)
    this.props.fetchUsers()
    console.log('this.props.fetchUSers')
  }

render() {
return (
    <button onClick={this.handleClick}>FetchUsers</button>
  )
}
}
o
function mapDispatchToProps(dispatch) {
  return bindActionCreators({ fetchUsers }, dispatch);
}

export default connect(null, mapDispatchToProps)(FetchUsers);
类FetchUsers扩展组件{
建造师(道具){
超级(道具);
this.handleClick=this.handleClick.bind(this);
}
handleClick(e){
e、 预防默认值();
console.log('thisporps',this.props)
this.props.fetchUsers()
console.log('this.props.fetchUSers')
}
render(){
返回(
获取用户
)
}
}
o
功能图DispatchToprops(调度){
返回bindActionCreators({fetchUsers},dispatch);
}
导出默认连接(null,mapDispatchToProps)(FetchUsers);
onClick我想要运行函数handleClick

在我的用户列表容器上的下一步,我希望从请求中收到该数据

import React, { Component } from 'react';
import { connect } from 'react-redux';

class UserList extends Component {
  renderList(userData) {
    console.log('userData', userData)
    return (
      <div>Bleh</div>
    );
  }

  render() {
    return (
      <table className="table table-hover">
        <thead>
          <tr>
            <th>user ID: </th>
            <th>Week Nr: </th>
            <th>Days number: </th>
            <th>User email: </th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
    );
  }
}

function mapStateToProps({ users }) {
  return {
    users: users
  }
}

export default connect(mapStateToProps)(UserList);
import React,{Component}来自'React';
从'react redux'导入{connect};
类UserList扩展组件{
renderList(用户数据){
console.log('userData',userData)
返回(
呜呜
);
}
render(){
返回(
用户ID:
第周:
天数:
用户电子邮件:
);
}
}
函数MapStateTops({users}){
返回{
用户:用户
}
}
导出默认连接(MapStateTops)(用户列表);

我不知道为什么在这个控制台上。log(userData)不工作,也没有收到任何数据。

在组件中声明您的道具!你在哪里调用了renderList函数?我认为您使用redux的方式不对。Redux用于在组件之间共享状态。看起来你应该使用侦听器。我粘贴了代码笔链接。我使用redux的方式如下:用户单击onClick按钮->action creator返回类型:USERS\u LIST->action creator返回一个操作,然后转到中间件,记录它->转到reducer,reducer处理该操作并返回新状态。我看不出在哪里调用renderList函数。好的,对。我没叫它。谢谢兄弟,我可以俯瞰它。。。