Skip to content

Commit 1e822d9

Browse files
author
Maya Vera
committed
converted component to functional component in the applyMiddleware docs example
1 parent b1120a6 commit 1e822d9

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

docs/api/applyMiddleware.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff 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';
176177
import { 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

195189
export default connect(state => ({

0 commit comments

Comments
 (0)