5 ms·
I appreciate this - some I've seen, some I'm a bit behind on. Cursory glance indicates some of this is convenience wrapping of some normal react patterns inste
by nkozyra 4y ago
I appreciate this - some I've seen, some I'm a bit behind on.
Cursory glance indicates some of this is convenience wrapping of some normal react patterns instead of a refactor of redux. Is that fair?
- acemarke 4y agoNo, RTK is a wrapper around just Redux patterns, not React. - store setup: `configureStore` creates a store with a good default config in one function call - Reducers: `createSlice` lets you define case reducers as functions in an object, write "mutating" syntax for immutable updates with Immer, and auto-generates the action creators for each reducer - Data fetching: `createAsyncThunk` abstracts the standard "dispatch actions before and after an async request" pattern - RTK Query: completely abstracts the _entire_ data fetching and caching process, adds cache entry lifecycles, auto-generates React hooks for use in components The only React-related bits in RTK are the auto-generated React hooks for RTK Query endpoints. Everything else is "here's all the same kinds of logic you've always written for Redux, but with 1/4 the code and good default behaviors". See https://redux.js.org/tutorials/fundamentals/part-8-modern-redux https://redux.js.org/tutorials/fundamentals/part-8-modern-re... and https://blog.isquaredsoftware.com/2022/06/presentations-modern-redux-rtk/ https://blog.isquaredsoftware.com/2022/06/presentations-mode... for overviews of what changes from legacy "hand-written" Redux to RTK and how to use the RTK APIs.