I am trying to optimize my React app in order to remove unnecessary renders.
Please refer to this Snack for an example: https://snack.expo.io/bUZpyw0kH
In this example app, there are two state variables stored in context. One of these values is updated every second, the other never changes.
What I am trying to wrap my head around is why console.log('rerender'); is called every second.
From my understanding, when you destructure variables stored in context, you only receive updates when the destructured variables change. I am only accessing otherValue, and not elapsed which changes every second. On this basis, why I am seeing console.log('rerender')?
In this instance, console.log('context child render'); isn't called every time because I have wrapped this component with React.memo.
Should I change this or is wrapping ContextChild in React.memo efficient enough? Do I need to split into multiple providers? And if I do, what if the component needs to access variables from both contexts?