Is there a pattern or way to get access to the wrapped component's this from within any of the composed methods?
For example, I would like to be able to do this:
withHandlers({
onError: props => (e) => {
this.setState({error: e})
}
})
if you want to do that, you may need to use withState(), so the code will be sth like this
javascript
withState('error', 'setError', null),
withHandlers({
onError: ({ setError }) => (e) => {
setError(e);
}
})
```
Let me know if it helps you 馃槈
But this puts them on the props object right? It seems like this library kind of forces you to use props for everything, but maybe I'm not using it correctly.
Do I have to change from a pattern like this:
Data.Query.run(q).then(results => results.requests)
.then(requests => this.setState({ requests, loading: false, error: undefined }))
.catch(e => this.setState({ error: e, loading: false }));
to
Data.Query.run(q).then(results => results.requests)
.then(requests => {
this.setState({ requests });
this.props.setError(undefined);
this.props.setLoading(false);
}
.catch(e =>
.then(requests => {
this.props.setError(e);
this.props.setLoading(false);
}
);
withState('state', 'setState', null),
withHandlers({
onSuccess: ({ setState }) => () => {
setState({ requests, loading: false, error: undefined });
},
onError: ({ setState }) => () => {
setState({ error: e, loading: false });
}
})
Always using props is much nicer, you are decoupling yourself from any particular api, since you are just calling a passed in prop.
Most helpful comment
Always using props is much nicer, you are decoupling yourself from any particular api, since you are just calling a passed in prop.