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

React hooks status? #2792

Closed
BruceL33t opened this issue Jul 11, 2019 · 15 comments
Closed

React hooks status? #2792

BruceL33t opened this issue Jul 11, 2019 · 15 comments

Comments

@BruceL33t
Copy link

Just started working with Relay and being used to working with modern React code (Context + Hooks), using render props and especially HoC seems like a step back in the stone-age.

So I'd really be interested in hearing about the status, and if possible and eta on a public hooks api? It would just make things a little more elegant ;-)

@taion
Copy link
Contributor

taion commented Jul 11, 2019

There are a couple of open-source libraries that add hook support for a good bit of Relay functionality. Take a look at https://github.com/relay-tools/relay-hooks and https://github.com/relay-tools/react-relay-mutation.

There are a few challenges in exactly matching the upcoming Relay hooks API. See relay-tools/relay-hooks#5 (comment) for more details.

@BruceL33t
Copy link
Author

@taion I know about relay-tools/relay-hooks, however it probably does not make sense to use them, if they differ so much from the hooks implementation that facebook is using internally right now. They might release their hooks implementation tomorrow, and we'd have to make huge refactors to migrate our code - hence this question. I was hoping to get an ETA on whe to expect being able to use hooks with Relay, without having to write our own or use a custom library, such as relay-tools :-)

@sibelius
Copy link
Contributor

You can always codemod

@JohannesKlauss
Copy link

Hooks got added few hours ago: b83aace

@sibelius sibelius closed this as completed Sep 4, 2019
@pie6k
Copy link

pie6k commented Sep 17, 2019

@JohannesKlauss while they're added to this repository - they're not yet published to npm.

@JohannesKlauss
Copy link

But now they are with 6.0.0

@sibelius
Copy link
Contributor

relay-experimental is taken on npm by another user

@pie6k
Copy link

pie6k commented Sep 17, 2019

@JohannesKlauss I've checked react-relay 6.0.0 and seems there are no hooks included there. Am I missing something?

@JohannesKlauss
Copy link

Oh sorry, yes. It's inside the relay-experimental package. My bad.

@pie6k
Copy link

pie6k commented Sep 17, 2019

So to confirm, there is no way to use them without building them manually from this repo at the current moment?

Looking at frequency of npm publishes, it's sad :)

6.0.0
a day ago
5.0.0
3 months ago
4.0.0
5 months ago
3.0.0
7 months ago
2.0.0
8 months ago

Anyway, IMO this issue should not be closed as hooks status seems unclear from outside user perspective

@JohannesKlauss
Copy link

@pie6k You can use this package: https://github.com/relay-tools/relay-hooks
It tries so be as close as possible to the current experimental implementation.

Also the release notes for 6.0.0 state, that those Hooks APIs are also very likely to change, hence they are experimental and not in the main package :).

@akomm
Copy link

akomm commented Oct 25, 2019

I would not recommend the relay-hooks library for everyone. It looks like relay-hooks does not even properly support @relay(plural: true). From the issue history and fixes on this matter it seems to me, they are not aware that react-relay library can also be used for stuff outside of relay connections, as the only checks in the code make edge/node structure assumptions as it seems. Typing-wise (TS) I also had to go from just using the the emitted fragment/query type to using those two plus the *$ref types on outer API of my components. All in all I dropped the usage of it. Hope for some first-class hook support, as hooks are awesome. Until than use my own hooks for that...

this

@sibelius
Copy link
Contributor

you can try relay hooks using experimental builds

https://relay.dev/docs/en/experimental/a-guided-tour-of-relay#installation

yarn add react@experimental react-dom@experimental react-relay@experimental

@akomm
Copy link

akomm commented Oct 25, 2019

@sibelius I try to avoid experimental if not dire needed. I have currently a solution which should be simple to migrate later when needed. Its tempting, but I pass out of experience.

@akomm
Copy link

akomm commented Oct 29, 2019

I got to correct my previous post. There were three issues that looked like one, one major on my side. Two resolved by the maintainer of the relay-hooks library very fast and the third by me. Other than this the hooks work perfectly well so far!

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

6 participants