Closed wtrocki closed 4 years ago
While I don't have a ton of experience with apollo-client yet I would hope we can make a HOC version along with a component version. IMO using a component with render props is really messy syntax wise and it mixes your data handling and presentational code in a way that is not desirable (harder to read and maintain, tightly coupled). Syntax is cleaner and concerns are better separated with a HOC in my opinion. Also from what I've seen so far Typescript appears difficult with the component version, type is never inferred on the props passed to render function.
Couple people raised their interest in this. Lets see if I can quickly hack something
I've spent some time today researching options for this. React hooks were introduced earlier this year and are quickly gaining popularity as an alternative to HOCs for building stateful components. react-apollo-hooks which is soon being moved to @apollo/react-hooks is a great example of how hooks can be used with Apollo Client for a really nice developer experience.
Ideally our OfflineClient
should be already compatible with the HOCs provided by react-apollo
and with react-apollo-hooks
for regular Mutations, Queries, Subscriptions. (Although a bit of testing is probably required)
To support the offline cases, the useMutation
hook could be a great reference/starting point for implementing our own useOfflineMutation
hook that would achieve the similar functionality but with the added ability to surface the various offline and conflict states from offix.
I'd love work on a prototype for this. I think one of our first steps could be to get some small sample application built with react that we can use for prototyping these ideas. (cc @wtrocki)
I think we need to make decision if we do sample application inside offix or use https://github.com/aerogear/offix-react-example repository. Then we can use it for investigation and supporting different flavours.
Fixed
Feature Request
React integration is needed to deliver better UX. We can have separate components like
OfflineMutation
etc.Looking for feedback.