React Redux Toolkit Tips

From bibbleWiki
Revision as of 03:39, 31 December 2022 by Iwiseman (talk | contribs) (Created page with "=Introduction= Taken from YouTube https://www.youtube.com/watch?v=NqzdVN2tyvQ =Tip 1= Instead of using <syntaxhighlight lang="js"> const posts = useSelector(state) => state.posts); </syntaxhighlight> We can use <syntaxhighlight lang="js"> // In the component const posts = useSelector(selectAllPosts) // In the Slice export const selectAllPosts = (state) => state.posts; </syntaxhighlight>")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

Taken from YouTube https://www.youtube.com/watch?v=NqzdVN2tyvQ

Tip 1

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;