in React JS by
Q:

How to dispatch an action on load?

1 Answer

0 votes
by

You can dispatch an action in componentDidMount() method and in render() method you can verify the data.

class App extends Component {
  componentDidMount() {
    this.props.fetchData()
  }

  render() {
    return this.props.isLoaded
      ? <div>{'Loaded'}</div>
      : <div>{'Not Loaded'}</div>
  }
}

const mapStateToProps = (state) => ({
  isLoaded: state.isLoaded
})

const mapDispatchToProps = { fetchData }

export default connect(mapStateToProps, mapDispatchToProps)(App)
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Jan 31, 2020 in Selenium by SakshiSharma
0 votes
asked Aug 27, 2020 in SAP by DavidAnderson
0 votes
asked Feb 9, 2020 in Big Data | Hadoop by rahuljain1
0 votes
asked Mar 2, 2020 in React JS by RShastri
0 votes
asked Jan 14, 2020 in QuickTest Professional (QTP) by GeorgeBell
...