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

Fetch user data for users table #94

Open
frattezi opened this issue Apr 12, 2024 · 0 comments
Open

Fetch user data for users table #94

frattezi opened this issue Apr 12, 2024 · 0 comments

Comments

@frattezi
Copy link

frattezi commented Apr 12, 2024

By using the endpoint created in #68 fetch all users and return data to the current /admin table

Using react-query make an custom hook, that will fetch user data for the user table in the admin's main page.

Quick Start - useQuery

Sample code:

export const useCustomQuery = ({ param }: { param: string }) => {
  const resolver = async () => {
    const response = await fetch(`/address?param=${param}`, {
      headers: { "Content-Type": "application/json" },
    });

    if (response.status >= 400) return {};
    const result = await response.json();
    return result?.data;
  };

  return useQuery<RegionData[]>(["counties", param], resolver, {
    enabled: !!param,
    staleTime: DefaultTimeMS.ONE_DAY,
  });
};
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