JustLogin JustLogin - 24 days ago 7
React JSX Question

What is the simpliest way to write data to store in React-redux?

I'm using React and Redux (and also Redux-thunk for async tasks) in my app. So, when I need to write some data to

store
as a result of
component
interaction, I use both
action
and
reducer
for this. But is it always necessary? Especially in the situations when there are no
connect
s to the modified field in
component
s? Do I always need
action
and
reducer
to write some data to
store
? Or, maybe, there's a method like
setState
in
store
?

Answer

Yes, it is necessary to write a action and a corresponding reducer to that action.

This is because Redux is built based on the Flux architecture. Flux architecture uses actions and reducers to modify a particular state in the state tree. So, it is required and you can't skip it.

If you feel this is too much of boilerplate code, you should try mobx