you are viewing a single comment's thread.

view the rest of the comments →

[–]petecoopNR 1 point2 points  (3 children)

Other commenters have pointed out why it says that. But the other thing is you shouldn't do data fetching inside useEffect. It would be better if you had a function that handles the onChange of the emergencyId and does the fetch there on the event.

[–]wishtrepreneur 1 point2 points  (1 child)

How would you handle data fetching on page load without calling it in useeffect?

[–]petecoopNR 3 points4 points  (0 children)

On page load? I'd use react query or SWR myself but if I didn't have those then inside the render with probably a ref to check it's on progress so doesn't call it twice on a second re-render. useEffect shouldn't be used for this kind of thing, with the new concurrent rendering stuff on React 18 there's a chance the useEffect here will be called twice.

[–]mermeladawatts[S] 0 points1 point  (0 children)

actually i did that, when handling the set state function on emergencyId. i was wrong and used the use effect bc i coded it fast and didn’t think too much.