A
A
alex4answ2020-12-06 13:44:41
React
alex4answ, 2020-12-06 13:44:41

Is it possible to mix Redux and Context?

Good afternoon, I ran into this issue.

There is a dashboard, on the main page there are charts and a choice of cut dates for these charts.
Accordingly, in Redux, storing this date is such a thing, because it works and is needed only for the main page.

I thought that it would be easier to forward the date in the turn of the context, is it possible to do this, is it adequate?

I think yes, because in the same styled component Context - ThemeProvider is used, but almost all the examples that I have seen, almost all the data is put in the redux store, whether they are needed only for 1 component (page) or are used globally (such as user data etc)

What are the advantages of the approach - store everything in the redux store ?
What are the advantages of the approach - forward through Context (if only required for 1 place)?

At times like this, I'm terribly slow

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Petrushenko, 2020-12-10
@alex4answ

If at level 1-2 I would use useState on the main component and prop it with props, I would wrap the child components in memo so that there would be no re-render when changing something else.
If we already ate more than 2 levels, then it’s better to put it in redux IMHO, and use useSelector to get selectors there. So at least the data in one place lies.
Judging by the approach that Dan Abramov advises with the advent of hooks, there is no longer any division into dumb and smart components as such, you can simply connect both components to the store and exchange data there.
Context should be used if it is some separate module with its own isolated data, and this separate module is used in some other modules (applications, in the case of a monorep, for example) and there is no way to store it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question