React Redux Toolkit Tips: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
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>"
 
Line 4: Line 4:
Instead of using  
Instead of using  
<syntaxhighlight lang="js">
<syntaxhighlight lang="js">
const posts = useSelector(state) => state.posts);
const posts = useSelector((state) => state.posts);
</syntaxhighlight>
</syntaxhighlight>
We can use
We can use

Revision as of 03:39, 31 December 2022

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;