How to dispatch an action on load?
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);
September 03, 2022
715
Read more
What is React?
November 06, 2022
ReactJSHow to programmatically trigger click event in React?
November 06, 2022
ReactJS