So I'm at a bit of a loss here for what to do and would love some recommendations.
I have a quizzing app that has a timer for a question. The parent contains the timer object which uses a callback to set the number of seconds remaining like so:
const [seconds, setSeconds] = React.useState<number>(null);
const timer = React.useRef<Timer>(new Timer({duration: 10, callback: i => setSeconds(i)}));
...
return (
<Context value={seconds}>
...
)
The parent passes the seconds around to the descendants through a context because a child and grandchild both need access to the number of seconds remaining to show a timer.
The problem is that the update interval is every .1 seconds, and as a result the children and all subsequent descendants rerender which is a huge issue.
Is there a way that I can only have only the things that rely on the timer rerender?
I have all of my components wrapped in React.useMemo and am accessing the seconds with React.useContext.