我正在尝试从调用该DeletePost函数
const mapDispatchToProps = (dispatch) => ({
DeletePost: () => dispatch(DeletePost())
});
但是,反应显示
无法读取未定义的属性“ props”
PostList.js
import {connect} from 'react-redux';
import {DeletePost} from '../actions/';
const Styles = {
myPaper: {
margin: '20px 0px',
padding: '20px'
}
}
const removePost = (id) => {
// showing error below this line cannot read props
this.props.DeletePost(id);
}
const PostList = ({props, posts}) => {
return (
<div>
{posts.map((post, i) => (
<Paper key={i} style={Styles.myPaper}>
<Typography variant="h6" component="h3">
{post.title}
</Typography>
<Typography component="p">
{post.post_content}
<h5>
by: {post.username}</h5>
<h5>
{moment(post.createdAt).calendar()}</h5>
</Typography>
<Button
variant="outlined"
color="primary"
type="submit"
onClick={removePost(post.id)}>
Remove
</Button>
</Paper>
))}
</div>
)
};
const mapDispatchToProps = (dispatch) => ({
DeletePost: () => dispatch(DeletePost())
});
export default connect(null, mapDispatchToProps)(PostList);
陪伴而非守候
相关分类