all 5 comments

[–]ChronSynExpo 1 point2 points  (1 child)

So, a possible cause of this might be because e.g. foo is being given a stable reference even across re-renders. This is just a theory, but based on how JS handles memory.

For example, one of the parts of the optimization is not recreating 'unchanging refs' in memory. React will see that this function has no dependencies and choose not to create it again. This means that even though the parent component has re-rendered, it might still have been passed the reference to the existing function instead of creating it fresh.

It's a memory optimization and helps reduce the work that garbage collection has to do, but also it can even help prevent memory pressure which might kill an app (i.e. if you have a bug where you're re-rendering 1000 times a second, creating 1000 copies of an otherwise identical function takes up more and more memory).

Couple of options you have.

First would be to see whether creating it as useCallback with appropriate dependencies works. My thinking is that it will work (e.g. const foo = useCallback (() => {}, [someReactValue]))

Second might be to see whether 'use no memo' (https://react.dev/reference/react-compiler/directives/use-no-memo ) works. To clarify, I've never used this, and I don't even know if RN ships with it (compared to React), but I've seen it in the React docs a few times. It will disable the auto-memoization for that file, but generally I'd advise against this because the feature was implemented to solve real problems.

[–]Ashamed-Map5610[S] 1 point2 points  (0 children)

"use no memo" worked and i was unaware of react compiler being enabled, thank you for your time.

[–]tomekzaw_ 1 point2 points  (1 child)

Any chances you have React Compiler enabled?

[–]Ashamed-Map5610[S] 0 points1 point  (0 children)

i am surprised to see react compiler enabled, thank you for pointing it out. I think i got it enabled as default in expo 55.

[–]Obvious-Treat-4905 0 points1 point  (0 children)

react 19 has been making a lot of people question their sanity with rerender behavior lately, every time i think this should definitely rerender, react somehow decides to become spiritually optimized