I am trying to redirect user to home page conditionally before component mounts:
componentWillMount(){
console.log("componentWillMount is called.")
let userHasNotChosenOpportunity = true
if (userHasNotChosenOpportunity) {
this.props.history.push("/home")
}
}
I have two problems:
componentWillMountnever gets calledcomponentWillMountis deprecated and there seems to be no alternative to execute code before component mounts.
Any suggestions?
You should try calling it on
componentDidMountor if you for some reason really need to usecomponentWillMountyou can useUNSAFE_componentWillMountbut as indicated it is unsafe