Skip to content
Discussion options

You must be logged in to vote

inside the onSuccess I am calling my components setItems, which causes the component to re-render, which in turn calls my useGetData hook to get called & then call my setState function again 🔄

because just re-rendering your component will not trigger onSuccess again. onSuccess is tied to data fetching, so it will only be called when a request is successfully made. Conceptually, onSuccess is Promise.then, onError is Promise.catch and onSettled is Promise.finally.

So the flow is:

  • mount triggers a fetch
  • calls onSuccess
  • calls setState
  • re-renders component
  • the end :)

You have also identified correctly why it doesn't work during render - that also violates the rule of react that render fun…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cliffordfajardo
Comment options

Answer selected by cliffordfajardo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants