T
TanStack3y ago
complex-teal

Is useEffect the best way to handle changes in data?

I have data that can change on the server and when it does I want certain things to happen in the app (such as opening a popup). I am currently handling this like this:
const fundingStatus = useFundingStatus()

useEffect(() => {
if (fundingStatus === 'CANCELED') {
startRefund()
return
}
if (fundingStatus === 'WRONG_FUNDING_AMOUNT') {
showWronglyFundedPopup()
return
}
}, [fundingStatus])
const fundingStatus = useFundingStatus()

useEffect(() => {
if (fundingStatus === 'CANCELED') {
startRefund()
return
}
if (fundingStatus === 'WRONG_FUNDING_AMOUNT') {
showWronglyFundedPopup()
return
}
}, [fundingStatus])
Is this the best way to achieve the idea of "onSuccess only for one instance" or is there some better way?
1 Reply
secure-lavender
secure-lavender3y ago
having https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose in mind this does seem like the way to go
Breaking React Query's API on purpose
Why good API design matters, even if it means breaking existing APIs in the face of resistance.

Did you find this page helpful?