diff --git a/reselect-example/src/app/components/HearthstoneCardList/index.js b/reselect-example/src/app/components/HearthstoneCardList/index.js index a4255f6..cdd1500 100644 --- a/reselect-example/src/app/components/HearthstoneCardList/index.js +++ b/reselect-example/src/app/components/HearthstoneCardList/index.js @@ -8,8 +8,8 @@ import HearthstoneCard from './components/HearthstoneCard'; import './styles.css'; class HearthStoneCardList extends Component { - componentWillMount() { - this.props.dispatch(hearthstoneActions.getHearthstoneCards()); + componentDidMount() { + this.props.getHearthstoneCards(); } render() { @@ -35,4 +35,8 @@ const mapStateToProps = store => ({ loading: store.hearthstone.cardsLoading }); -export default connect(mapStateToProps)(HearthStoneCardList); +const mapDispatchToProps = dispatch => ({ + getHearthstoneCards: () => dispatch(hearthstoneActions.getHearthstoneCards()) +}); + +export default connect(mapStateToProps, mapDispatchToProps)(HearthStoneCardList); diff --git a/reselect-example/src/app/index.js b/reselect-example/src/app/index.js index 26844f4..21f5cf3 100644 --- a/reselect-example/src/app/index.js +++ b/reselect-example/src/app/index.js @@ -7,9 +7,9 @@ import hearthstoneActions from '../redux/hearthstone/actions'; import HearthstoneCardList from './components/HearthstoneCardList'; class App extends Component { - componentWillMount() { + componentDidMount() { setInterval( - () => this.props.dispatch(hearthstoneActions.otherAction()), + () => this.props.otherAction(), 500 ) } @@ -28,4 +28,8 @@ const mapStateToProps = store => ({ tickCount: store.hearthstone.count }); -export default connect(mapStateToProps)(App); +const mapDispatchToProps = dispatch => ({ + otherAction: () => dispatch(hearthstoneActions.otherAction()) +}); + +export default connect(mapStateToProps, mapDispatchToProps)(App); diff --git a/unmount-state-loss/src/app/components/IncrementalCounter/index.js b/unmount-state-loss/src/app/components/IncrementalCounter/index.js index 9c458d5..ac4adf8 100644 --- a/unmount-state-loss/src/app/components/IncrementalCounter/index.js +++ b/unmount-state-loss/src/app/components/IncrementalCounter/index.js @@ -3,7 +3,7 @@ import React, { Component } from 'react'; class IncrementalCounter extends Component { state = { value: 0 }; - componentWillMount() { + componentDidMount() { setInterval( () => this.setState(prevState => ({ value: prevState.value + 1 })), 1000 diff --git a/using-purecomponent/src/app/index.js b/using-purecomponent/src/app/index.js index 5c4b002..830d5db 100644 --- a/using-purecomponent/src/app/index.js +++ b/using-purecomponent/src/app/index.js @@ -12,7 +12,7 @@ class App extends Component { otherProps: { password: '1234' } }; - componentWillMount() { + componentDidMount() { setInterval( () => { this.setState(prevState => ({ counter: prevState.counter + 1 }));