jezsung / query

A server state management library for Flutter.
10 stars 0 forks source link

Flutter-Hooks #2

Open Phenek opened 1 month ago

Phenek commented 1 month ago

Hello

I would like to know if you will accept my help to make your librairy use flutter_hooks package?

I think it could be a game changer

It would look like this: React.js react-query V5

  const { isPending, error, data } = useQuery({
    queryKey: ['repoData'],
    queryFn: () =>
      fetch('https://api.github.com/repos/TanStack/query').then((res) =>
        res.json(),
      ),
  })

Dart

    final getRepoDataQuery = useQuery(
      queryKey: ['repoData'],
      queryFn: () => await http.get(Uri.parse('https://api.github.com/repos/TanStack/query')),
      );

     // You can use it like so then:

     if (getRepoDataQuery.isPending) return Loader(..);
     if (getRepoDataQuery.isError) return ErrorWidget(getRepoDataQuery.error);

     return DataWidget(getRepoDataQuery.data)

It will handle cache, staleTime, (onSuccess, onError) callbacks.

I already implemented this kind of similare hooks like useMutation, useInfiniteQuery.

The main idea would be to copy react-query api, but for sur we will make it better!

Let me know,

Regards ;)

jezsung commented 1 month ago

@Phenek

Thank you for your suggestion. This repo already has a package that utilizes the flutter_hooks package.

You can find various hooks under the path packages/flutter_query/lib/src/hooks. Please take a look at those hooks first.

Since this package has been unmaintained for a while, I'm willing to change the whole codebase if you can make PRs with improvement.

Phenek commented 2 weeks ago

Glad to see you around @jezsung!

First, I am mastering my hooks for a V1 production Flutter App that should be on stores in September. This app is designed like a respective React.js web app, using React Query. That's why I am managing to have the same behaviors/design as TanStack Query v5.

I will let you know when I am ready to really work on a PR and work together. I should start during/after September, if Stars are aligned ✨.