Good day.

I am writing an application React + Redux . My component looks like this:

 import React from 'react'; class HeaderContainer extends React.Component { onGetBtnClick(e) { this.props.loadPresentations() } render() { console.log(this.props); return ( <div> <h1>Header</h1> <button className='btn' onClick={this.onGetBtnClick}>loadPresentations</button> </div> ); } } export default HeaderContainer; 

In this case, the browser log displays:

 Object {user: Object, loadPresentations: function} 

Those. the loadPresentations function is there. And I can not call her. Writes

Uncaught TypeError: Cannot read property 'props' of null.

But user can.

Can you please tell me how to call Action ?

  • In the case of using es6 classes in the reactor, it does not autobind methods to the component instance as opposed to React.createClass - Duck Learns to Take Cover
  • 1. actions need to be imported 2. they need to be dispatched, not as a normal function to call - greybutton
  • one
    That is, you either need to write in the constructor of the class this.onGetBtnClick = this.onGetBtnClick.bind (this) (preferably) or in the onClick handler = {this.onGetBtnClick.bind (this} - Duck Learns to Take Cover
  • There is also a chance that this answer may help you a little ru.stackoverflow.com/questions/637479/… - Duck Learns to Take Cover
  • Also as already mentioned @greybutton by the redox in this particular piece of code does not smell) In the question heading one thing, in the question is another - Duck Learns to Hide

0