4 ms·
I've been using Redux for many years so I just skipped to the last part (I'll probably read the rest tho, I'll surely learn something). Strangely, I've never no
by ggregoire 6y ago
I've been using Redux for many years so I just skipped to the last part (I'll probably read the rest tho, I'll surely learn something). Strangely, I've never normalized the data in my apps. I knew the technique but it has never been a performance bottleneck for us. But I can see how convenient it could be anyway (looking up a specific item instead of finding it). Also, we have been writings selectors but very few actually, we should definitely make it the norm. We write a lot of collection filtering, mapping and reducing directly in our connects.
> Out of curiosity, anything specific in that page you found particularly helpful?
I liked how you demonstrated rerendering issues (illustrated with the profiler tool) and applied those techniques (selectors, normalization) to fix them.
-
Just for the anecdote, slightly off-topic, I wrote like 3 years ago some Redux helper functions very similar to what you did with React Toolkit. We have 3 functions createResourcesActions, createResourcesReducers and createResourcesSagas, which take an array of strings describing our resources and return the corresponding actions, reducers and sagas (we fetch about 50 different types of resources). Something like
const resources = ['users', 'posts', 'comments']
const { usersActions, postsActions, commentsActions } = createResourcesActions(resources)
const { usersReducer, postsReducer, commentsReducer } = createResourcesReducers(resources)
const { usersSagas, postsSagas, commentsSagas } = createResourcesSagas(resources)
combineReducers({ users: usersReducer, posts: postsReducer, comments: commentsReducer })
sagaMiddleware.run(/* register the sagas */)
connect(state => ({ posts: state.posts.items }), { fetchPosts: postsActions.fetchResources })(PostsList)
It was funny to see you release something very similar. :) It definitely helps a lot to deal with all the boilerplate.
- acemarke 6y ago> I liked how you demonstrated rerendering issues (illustrated with the profiler tool) and applied those techniques (selectors, normalization) to fix them. Great, that's _exactly_ what I was trying to accomplish! > It was funny to see you release something very similar It's actually not surprising at all :) Redux Toolkit was specifically designed to solve the most common problems that people were experiencing while using Redux, and we've taken inspiration from many of the third-party libraries that the community had already created (because those libs were created to solve the same kinds of problems, and gave us ideas for what kinds of APIs people were writing). For more background, see my post "Redux Toolkit 1.0", which talks about the discussions, issues, and ideas that inspired Redux Toolkit, how we evolved and designed its APIs, and the vision and goals behind its design: https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-1.0/ https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-...