U
U
Username2018-08-21 11:59:32
React
Username, 2018-08-21 11:59:32

Why is routing not working due to action in React-Redux?

Good afternoon, in the React application, I have an onLoad event hanging, which takes the width and height of the parent and divides by a constant value and is dispatched to the storage through the action.
And because of this, routing does not work. What can be wrong?
Component
5b7bd3afd189e977411512.pngAction
5b7bd3e6e2f9c229951440.pngReducer
5b7bd42a3f89d759698787.png
And why do you need to write an action if you can directly call the dispatcher without intermediaries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-08-21
@dalv_happy

And because of this, routing does not work.

What exactly is not clear? Why write a function? Or why not manually import store into each component?
First, don't repeat yourself. Secondly, now the components do not know anything about the store and its storage location, otherwise they will. But no one bothers you to do as you please.
redundant design:
dispatch => ({
  onSetScale: (event) => {
    dispatch(setScale(event);
  }
})

Can be shortened to:
{
  onSetScale: setScale,
}

I don't pass actions via connect, but call like this:
componentDidMount() {
  this.props.dispatch(action());
}

The advantage of this solution is that you can quickly jump to the place where the action is declared. In large projects, this saves a lot of time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question