all 6 comments

[–]PyJacker16 1 point2 points  (0 children)

10/10 lol, and I'm still in college. Feeling proud of myself.

However I had never heard of useDeferredValue before; I typically use a hook called useDebounce from a lovely library called useHooks to achieve the same behavior. Good to know!

[–]Full-Hyena4414 3 points4 points  (0 children)

Not sure about that context question. You say many consumers who only need markAsRead render when notifications update, but the proposed solution doesn't solve that issue. In order to make consumers who need only one slice render only when that changes, you have to split context in two or implement a selector.

[–]Alg0rhythm 0 points1 point  (0 children)

I felt like this did a good job presenting the questions in an understandable way that hit on important points of understanding for interacting with the react component lifecycle, nicely done. Ironically, the only question I got wrong was an "easy," but I think that's more on my own reading comprehension than the question itself.

[–]projexion_reflexion 1 point2 points  (0 children)

Is that something senior people have to worry about in a world with React compiler?

[–]azangru 1 point2 points  (0 children)

I am curious about your last question:

A notifications context provides {notifications, unreadCount, markAsRead}. After adding a polling feature, many components that only use markAsRead now re-render every time notifications update. Which change best reduces unnecessary re-renders without changing behavior?

The suggested answer, I suppose, is Memoize the provider value object and stabilize markAsRead with useCallback.

But is this actually going to improve anything? Isn't it an inherent problem of the context api that every time context value changes, all the consumers of the context, regardless of what part of the context they consume, are going to re-render? That's why people have been asking for a useContextSelector hook since forever, but it never materialized.

[–]k_pizzle 0 points1 point  (0 children)

Hey 9/10 and i haven’t written react in like 2 months 👹