Coming soon - Get a detailed view of why an account is flagged as spam!
view details
0
Is there a way to send a signal that isn't a boolean to trigger a useEffect?
Post Flair (click to view more posts with a particular flair)
Post Body

I don't know if this is possible (or recommended), but I'm looking for a way to trigger some code, much like how an event handler triggers a function call. Something like this:

``` const Context = createContext(null); function Parent() { const onSave = async () => { const res = await someMutationFunction(); if (res.success) { // trigger child component } } return ( <Context.Provider value={// what to put in here?}> <Child /> </Context.Provider> ) }

function Child() { const context = useContext(Context);

// context should trigger this effect useEffect(() => { }, [context]); } ```

Right now I have a boolean that flips to true, then back to false in 100 ms: const [isUpdated, setIsUpdated] = useState(false); if (res.success) { setIsUpdated(true); setTimeout(() => setIsUpdated(false), 100); }

But is there a better way of doing this?

Author
Account Strength
90%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
993
Link Karma
510
Comment Karma
483
Profile updated: 2 months ago
Posts updated: 2 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago