relay-tools / relay-hooks

Use Relay as React hooks
https://relay-tools.github.io/relay-hooks/docs/relay-hooks.html
MIT License
542 stars 56 forks source link

Migration advices from version 3 to version 4 #144

Closed aleksandrlat closed 3 years ago

aleksandrlat commented 3 years ago

@morrys I just noticed you released stable version 4. Great work! Thank you!

Do you have any advices for migrating from version 3.7.0 to version 4.0.0?

Or this is enough to know?

Breaking Changes
- removed support to Mutation HOC
- useRefetch no longer exists
- remove fetchObserver in useQuery in favor of onComplete property
- changed the return type:
  - useQuery -> const { data, isLoading, error, retry} = useQuery(query, variables); (removed cached and added isLoading)
  - useRefetchable -> const { data, refetch, isLoading, error } = useRefetchable(node, ref); (before [data, refetch])
  - usePagination -> const { data, hasNext, isLoadingNext, hasPrevious, isLoadingPrevious, isLoading, refetch, loadNext, loadPrevious, errorNext, errorPrevious, error } = usePagination(node, ref); (before [ data, { isLoading, hasMore, loadMore } ])
- usePagination now uses the @refetchable directive

Thanks in advance!

morrys commented 3 years ago

Hi @aleksandrlat, in these two PRs I made the migrations of 2 example projects: https://github.com/relay-tools/relay-hooks/pull/133/files https://github.com/relay-tools/relay-hooks/pull/134/files

We can use this issue to add useful information to the migration.

aleksandrlat commented 3 years ago

Main change for us was useQuery returns data now instead of props.

Also I could not migrate usePagination yet because our fragment is not "refetchable". I will return back to it later.

morrys commented 3 years ago

Also I could not migrate usePagination yet because our fragment is not "refetchable". I will return back to it later.

Could you explain better?

n1ru4l commented 3 years ago

I just migrated and the new usePagination hook is so much nicer! The @refetchable directive is super powerful!

morrys commented 3 years ago

I close the issue as the most used version of relay-hooks is 4.2.0