잠시 동안 요소 중 하나를 렌더링해야하는 양식이 있습니다. 나는 componentDidMount
에서이 목표를 위해 setTimeout
를 사용하지만 구성 요소는 아마, 어떤 시점에서 다음 시간 제한이 종료 마운트 해제됩니다 setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the undefined component.
React js 지연 렌더링 오류가 발생합니다.
class Form extends React.Component {
constructor(props, context) {
this.state = {resend: false};
}
componentDidMount() {
const max = 3;
if (this.props.count < max) {
setTimeout(() => {
this.setState({resend: true});
}, 1000);
}
}
render() {
return (
<form>
...
{this.state.resend ? <Component/> : null}
</form>
);
}
}
감사! 내 문제를 해결하는 데 도움이되었습니다. – MyName