Hi! I'm fairly new to react development so sorry if the question is amateur. In these cases what I usually do is that I just get the user in maybe a useEffect hook, and just handle the mount case (when there's no user set yet) with a conditional. Am I doing it wrong, or just inelegant?
Hi Richard, I'm not sure what you mean. What I do in this example is the same as fetching the user in a useEffect hook:
useDidMount is just a custom hook that uses the useEffect hook. And because it uses the useEffect hook with no dependencies it can ensure that the callback is only executed ones i.e. after mount.
So, also in this example you would probably handle the mount case with a conditional for your component rendering.
Hi! I'm fairly new to react development so sorry if the question is amateur. In these cases what I usually do is that I just get the user in maybe a useEffect hook, and just handle the mount case (when there's no user set yet) with a conditional. Am I doing it wrong, or just inelegant?
Hi Richard, I'm not sure what you mean. What I do in this example is the same as fetching the user in a useEffect hook:
So, also in this example you would probably handle the mount case with a conditional for your component rendering.
Ah, I see, then I just misunderstood useDidMount, thanks for the answer!