React Redux Toolkit Tips: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=Introduction= | =Introduction= | ||
Taken from YouTube https://www.youtube.com/watch?v=NqzdVN2tyvQ | Taken from YouTube https://www.youtube.com/watch?v=NqzdVN2tyvQ | ||
=Tip 1= | =Tip 1 Probably should know this= | ||
Instead of using | Instead of using | ||
<syntaxhighlight lang="js"> | <syntaxhighlight lang="js"> |
Revision as of 03:45, 31 December 2022
Introduction
Taken from YouTube https://www.youtube.com/watch?v=NqzdVN2tyvQ
Tip 1 Probably should know this
Instead of using
const posts = useSelector((state) => state.posts);
We can use
// In the component
const posts = useSelector(selectAllPosts)
// In the Slice
export const selectAllPosts = (state) => state.posts;