3 ms·
This is not my experience at all. I had senior developers, who have worked with RTK before, misusing simple features such as the "createSlice" API. By contras
by mikojan 4y ago
This is not my experience at all.
I had senior developers, who have worked with RTK before, misusing simple features such as the "createSlice" API.
By contrast, I have never once sat down with a junior to walk through React's Context. I assume, they just read the docs and were good to go.
- acemarke 4y agoI'm genuinely curious - do you have any examples of "misusing `createSlice`"? FWIW I see folks misusing / misunderstanding Context on a near-daily basis, mostly around misunderstanding what components will re-render and when. That's part of what led me to write my "Guide to React Rendering Behavior" post, to clarify when/why/how React renders: - https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/ https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-...
- mikojan 4y agoA common issue with "createSlice" even with seasoned developers is they're introducing useless nesting and weird imperative-functional constructs because they fundamentally do not understand how "immer" works. I've read your blog post, and I might be missing something, but you do not seem to be highlighting any re-rendering issues specific to context. Juniors will have to learn how React works anyway. Context or not.
- acemarke 4y agoThe usual misunderstandings about context are: - Thinking that if you change a field in the context value only components that read that field will re-render - Thinking that _only_ the components that consume the context will re-render, not realizing that normal recursive rendering behavior resumes from there - Not realizing that updating a context requires a `setState` call in the parent that renders the `<MyContext.Provider>`, and you can easily end up in a situation where the _entire_ component tree renders just because of default recursive rendering Can you point to some examples of the "useless nesting" and "weird constructs" you're referring to? I'm curious to see what's happening, and if there's any docs improvements we can add to help provide guidance.
- mikojan 4y agoThese "misunderstandings about context" are not specific to context. React developers will have to learn about them whether they are using context or not. > Can you point to some examples of the "useless nesting" and "weird constructs" you're referring to? Example: Create a slice with a list of items as initial state and truncate it in a reducer.