I have a problem with typescript. Can you please tell me how to rewrite the useEffect hook from "nextProps" (jsx) to typescript (tsx)?
useEffect((nextProps) => {
if (nextProps.selectedProviderJob !== selectedProviderJob) {
setState({
trackingEventOrder: "",
nextNote: "",
selectedSubpayers: [],
approvalDate: null,
followUpDate: null,
isApproved: false,
isPending: false,
providerNumber: nextProps.selectedProviderJob.providerNumber,
});
}
}, [props]);
The useEffect hook does not get any return type, so there is no type to set. In addition to that, using props in the second argument of the useEffect could cause heavy workload and reloading if there are more props passed to the component. So I would not recommend that if you are relying on only one variable.
I have to correct this answer. The useEffect-method has a return type. You can pass a method which will run when the component gets destroyed. But that is not needed in your case.
useEffect(() => {[function that returns nothing]}, [variables which trigger the hook by change]);