Reactjs 带重新组合()的异步示例?
我有下面的代码可以完全工作,尽管其中的一部分(_FetchJSON)是一个在重组之外的定制HOC (现场演示@) 好了:Reactjs 带重新组合()的异步示例?,reactjs,recompose,Reactjs,Recompose,我有下面的代码可以完全工作,尽管其中的一部分(_FetchJSON)是一个在重组之外的定制HOC (现场演示@) 好了: const fetchJson = compose( withStateHandlers(null, { onData: state => data => ({ jsonData: data }) }), lifecycle({ componentDidMount() { fetch(this.props
const fetchJson = compose(
withStateHandlers(null, {
onData: state => data => ({
jsonData: data
})
}),
lifecycle({
componentDidMount() {
fetch(this.props.request)
.then(response => response.json())
.then(data => this.props.onData(data));
}
})
);
谢谢是的,我错过了WithStateHandler回调所期望的(state,props)=>payload=>{},而不仅仅是(state,props)=>{};)
const _FetchJson = compose(
withStateHandlers(undefined,
{
onData: state => ({
jsonData: state
})
}),
lifecycle({
componentDidMount() {
fetch(this.props.request)
.then(response => response.json())
.then(this.props.onData.bind(this));
}
})
);
const fetchJson = compose(
withStateHandlers(null, {
onData: state => data => ({
jsonData: data
})
}),
lifecycle({
componentDidMount() {
fetch(this.props.request)
.then(response => response.json())
.then(data => this.props.onData(data));
}
})
);