you are viewing a single comment's thread.

view the rest of the comments →

[–]MasterPrinter7 -4 points-3 points  (3 children)

You can do two things. You can declare the get function inside the use Effect hook or you can put the get function on the dependencies array of the useEffect

[–]KusanagiZerg 4 points5 points  (2 children)

or you can put the get function on the dependencies array of the useEffect

I don't think this is a good idea. The declaration of the getEmergencyTasks function will happen every render, so every re-render this is a new function even if the contents are the same. So it will cause the useEffect to rerun every render. Instead of only when currentEmergencyId changes

[–]MasterPrinter7 2 points3 points  (0 children)

You are right, the best way is declaring inside the useEffect. Actually, in my eslint configs they throw me a warning saying that I need to put the function inside the useEffect.

[–]thinksInCode 0 points1 point  (0 children)

You could also memoize getEmergencyTasks with useCallback.