score:1

Accepted answer
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { loadingData } from './loading';

class MyComponent extends Component {
  constructor(props){
    super(props)

    this.onLoadingData = this.onLoadingData.bind(this)
  }

  componentDidMount() {
    this.props.loadingData('no more undefined')
  }

  onLoadingData() {
    this.props.loadingData('DATA')
  }

  render() {
    console.log(this.props.loading)
    return (
      <div>
        <h2>MyComponent</h2>
        <button onClick={this.onLoadingData}>Load Data</button>
        <p>{this.props.loading}</p>
      </div>
    );
  }
}

const mapStateToProps = (state) => {
  return {
    loading: state.loading
  }
}

const mapDispatchToProps = {
  loadingData
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(MyComponent)

Related Query

More Query from same tag