-
-
Save brigand/02bbab1892392a0cbb22138cd08609e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetchesDataOnMount = (callback) => (C) => class DataFetcher extends React.Component { | |
constructor(props) { | |
super(props); | |
if (__SERVER__) callback(this.props); | |
} | |
componentDidMount() { | |
if (!__SERVER__) callback(this.props); | |
} | |
render() { | |
return <C {...this.props} />; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends React.Component { | |
// ... | |
componentWillReceiveProps(nextProps) { | |
if (nextProps.id !== this.props.id) fetchData(nextProps); | |
} | |
}; | |
const fetchData = (props) => props.fetchData(props.id); | |
let Wrapped = C; | |
Wrapped = connect(...)(C); | |
Wrapped = fetchesDataOnMount(fetchData)(C); | |
export default Wrapped; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment