Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use render props instead of HOC-style connect? #207

Open
ianstormtaylor opened this issue May 24, 2018 · 0 comments
Open

Use render props instead of HOC-style connect? #207

ianstormtaylor opened this issue May 24, 2018 · 0 comments

Comments

@ianstormtaylor
Copy link

First off, thank you for this library, it is awesomely simple!

I've been toying with react-apollo and the new <Query> and <Mutation> components, and they are really nice in terms of making data declarative, allowing you to co-locate data requirements inside your components.

I was thinking it would be really nice is react-refetch was architected similarly. Instead of connect(mapPropsToRequests, Component), it would be cool do to:

<Refetch
  url={`/users/${id}`}
  method="GET"
>
  {(fetch) => (
	return fetch.pending ? (
      <LoadingAnimation />
    ) : fetch.rejected ? (
      <Error error={fetch.reason} />
    ) : (
      <User={fetch.data} />
    )
  )}
</Refetch>

Or even, for non-GET methods, offer a mutation API:

<Refetch
  url={`/users/${id}`}
  method="POST"
>
  {(updateUser, fetch) => (
	return fetch.rejected ? (
      <Error error={fetch.reason} />
    ) : (
      <Button isLoading={fetch.pending} onClick={updateUser}>Save</Button>
    )
  )}
</Refetch>

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant