Reactjs 在react using post list中显示帖子的创建者名称

Reactjs 在react using post list中显示帖子的创建者名称,reactjs,api,ecmascript-6,redux,es6-promise,Reactjs,Api,Ecmascript 6,Redux,Es6 Promise,我正在创建一个帖子列表,在react和 用户和发布API 我的动作文件 export const fetchuser = (id) => async dispatch => { const response = await instance.get(`./users/${id}`) dispatch({ type : "GET_USERS", payload :response.data

我正在创建一个帖子列表,在react和

用户和发布API

我的动作文件

 export const fetchuser = (id) => async dispatch => {
        const response = await instance.get(`./users/${id}`)
        dispatch({
            type : "GET_USERS",
            payload :response.data
        })
    }
我的组件

import React, { Component } from 'react'
import {fetchuser} from '../actions'
import { connect } from 'react-redux'

class Postuser extends Component {
    componentDidMount(){
        this.props.fetchuser(this.props.userid)
    }
    render() {
        const user = this.props.users.find((user) => user.id === this.props.userId);
        if(!user){
            return null
        }
       return <div>{user.name}</div>
    }
}
const mapStateToProps = state => {
    return {
       users:state.users 
    }
}
export default connect(mapStateToProps,{fetchuser})(Postuser)
 <Postuser userId={post.userId} />
使用此组件的父组件

import React, { Component } from 'react'
import {fetchuser} from '../actions'
import { connect } from 'react-redux'

class Postuser extends Component {
    componentDidMount(){
        this.props.fetchuser(this.props.userid)
    }
    render() {
        const user = this.props.users.find((user) => user.id === this.props.userId);
        if(!user){
            return null
        }
       return <div>{user.name}</div>
    }
}
const mapStateToProps = state => {
    return {
       users:state.users 
    }
}
export default connect(mapStateToProps,{fetchuser})(Postuser)
 <Postuser userId={post.userId} />


我收到这个错误消息,请检查

ET 404 2createError.js:17未捕获(承诺中)错误:请求失败 状态代码404 在createError(createError.js:17) 结算时(结算js:19) 在XMLHttpRequest.handleLoad(xhr.js:60)


好的,您做错了,您将用户ID作为

 <Postuser userId={post.userId} />
希望能有帮助