V
V
Vadim Stepanenko2021-03-15 16:08:12
React
Vadim Stepanenko, 2021-03-15 16:08:12

Multiple useSelectors or one shared one?

Hey!

The router has its own separate reducer and actions. In App.js, you need to get data from routerReducer.js, namely: page, url, metas, etc.

Actually, what is the best way to do this: use several useSelectors or one common one?

const router = useSelector((state) => state.router);

// или

const page = useSelector((state) => state.router.page);
const url = useSelector((state) => state.router.url);
const metas = useSelector((state) => state.router.metas);


In general, the first option is more convenient - there is less code, but maybe there are some pitfalls?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denioo, 2021-03-15
@Denioo

const {url, page, metas} = useSelector(({router}) => router);

A
Andrey Okhotnikov, 2021-03-15
@tsepen

const { page, url, metas } = useSelector((state) => state.router);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question