我如何才能用笑话来对componentWillReceiveProps(nextProps)进行单元测试?
componentWillReceiveProps(nextProps) {
if (nextProps.data === undefined ||
nextProps.data.hasOwnProperty('error') ||
nextProps.err !== undefined) {
this.setState({
messageError: "Something went wrong!"
});
} else if ((nextProps.data).length) {
this.setState({
dataArray: nextProps.data
});
}
}
答案 0 :(得分:1)
但是我建议您将代码从componentWillReceiveProps移至shouldComponentUpdate,因为CWRP已弃用。