3

In the below code the useEffect changes to loaded state to true when the component is loaded

  let [loaded, setLoaded] = useState(false);
  console.log(props.result.meanings);

  useEffect(() => {
    setLoaded(true);
  }, [props.result]);

if (loaded) { \\ the rest of the code

and this will cause a problem because it enters an if condition where the props value is not assigned from the parent component yet.

Sophie
  • 29
  • 3

1 Answers1

-1

I managed to solve this issue by simply creating a condition : if (props.result) {}. This way it only is true when the props is NOT null and actually receive a value from the parent component.

I removed the useEffect entirely. it seems in that situation it was unnecessary and the problem was solvable with a simpler approach. thanks for the replies.

Sophie
  • 29
  • 3