【发布时间】:2021-04-19 12:05:34
【问题描述】:
我正在尝试使用 MERN 堆栈将错误消息从后端带到前端。我能够在开发人员工具中接收错误消息,但无法在 UI 中显示消息。我正在使用 Redux 作为状态管理器。当我提交表单时,concomponentDidUpdate 中的 console.log() 不起作用。有人可以澄清我的代码有什么问题吗?
state = {
name: '',
email: '',
phoneNo: null,
dateOfBirth: new Date,
gender: 'Select',
education: '',
checkBox: false,
msg: null
}
static propTypes = {
addInfo: PropTypes.func.isRequired,
info: PropTypes.object.isRequired,
error: PropTypes.object.isRequired
}
componentDidUpdate(prevProps, nextProps) {
const { error } = this.props;
if (error !== nextProps.error) {
console.log("Working");
if (error.id === 'REGISTER_FAIL')
this.setState({ msg: error.msg.msg });
else
this.setState({ msg: null });
}
}
【问题讨论】:
标签: node.js reactjs mongodb express redux