Answer the question
In order to leave comments, you need to log in
How to properly use useSelector and store.getState?
I saw a lot of opinions on this subject, including leads from our project.
I would like to understand in more detail when and what we use, and how it is better not to do it.
There are options:
// 1
const { name, age } = useSelector(state => state.userInfo);
// 2
const name = useSelector(state => state.userInfo.name);
const age = useSelector(state => state.userInfo.age);
// 3
const [name, age] = useSelector((state) => [
state.userInfo.name,
state.userInfo.age,
]);
const userInfo = useSelector(state => state.userInfo);
// or
const { userInfo } = store.getState();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question