File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed
Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -173,23 +173,17 @@ store
173173// I can also dispatch a thunk async action from a component
174174// any time its props change to load the missing data.
175175
176+ import React from ' react' ;
176177import { connect } from ' react-redux'
177- import { Component } from ' react'
178178
179- class SandwichShop extends Component {
180- componentDidMount () {
181- this .props .dispatch (makeASandwichWithSecretSauce (this .props .forPerson ))
182- }
179+ function SandwichShop (props ) {
180+ const { dispatch , forPerson } = props;
183181
184- componentDidUpdate (prevProps ) {
185- if (prevProps .forPerson !== this .props .forPerson ) {
186- this .props .dispatch (makeASandwichWithSecretSauce (this .props .forPerson ))
187- }
188- }
182+ useEffect (() => {
183+ dispatch (makeASandwichWithSecretSauce (forPerson));
184+ }, [forPerson]);
189185
190- render () {
191- return < p> {this .props .sandwiches .join (' mustard' )}< / p>
192- }
186+ return < p> {this .props .sandwiches .join (' mustard' )}< / p>
193187}
194188
195189export default connect (state => ({
You can’t perform that action at this time.
0 commit comments