Next.js Discord

Discord Forum

How to use useEffect and useCallback together and achieve memoization ?

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Original message was deleted.

3 Replies

code example?
Wool sower gall maker
yeah, code example would help
@DirtyCajunRice | AppDir code example?
Spectacled bear
The code is very long but this is the best example i can give for clarifaction:

  const focus = useCallback(async () => {
    await core.delay(10)
    titleRef.current?.setNativeProps({
      hasTVPreferredFocus: true,
    })
  }, [focusStore.screen])


I have a Card component, and its rendered many times in the app, i want the Card components to run the focus function every time the [focusStore.screen] changes, but when i do this i useEffect, it runs like 100 times and is not performant at all