useEffect trigger twice when slice Pattern,I don't want the first trigger #2837
-
shopPage.ts triggers useEffect twice. The defaultShopInfo outputted by the first trigger is wrong, which is what I don't want to happen. The second trigger is correct, and it is the page that triggers syncShopInfo. How can I avoid the first trigger? Log Output:
shopPage.ts
shopStore.ts
shopAdminStore.ts
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
@felix9ia that's how works React, |
Beta Was this translation helpful? Give feedback.
-
Thank you for replying me so quickly. I hope it’s not a problem with the way I write slice. I can only think of other solutions. |
Beta Was this translation helpful? Give feedback.
@felix9ia that's how works React,
useEffect
is a way to sync your data with something else. BTW, you can usesubscribe()
trigger something when something else change