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

Add a useApi hook for accessing the current api client without having a reference to it #217

Merged
merged 1 commit into from
Jun 26, 2023

Conversation

airhorns
Copy link
Contributor

@airhorns airhorns commented Jun 26, 2023

We need this for the auth helpers that ideally don't need to be passed an instance of the api every time, like:

export const useSession = () => {
  const api = useApi();
  const [{ data, fetching, error }] = useGet(api.currentSession, {
    select: {
      id: true,
      state: true,
      createdAt: true,
      userId: true
    }
  });
  return data;
}

With this hook, we can export that kind of framework code, and rely on the user <Provider/>-ing us the api client we need

@airhorns airhorns marked this pull request as ready for review June 26, 2023 02:22
@airhorns airhorns requested a review from jasong689 June 26, 2023 02:22
Copy link
Contributor

@jasong689 jasong689 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@airhorns airhorns merged commit 7a542eb into main Jun 26, 2023
@airhorns airhorns deleted the use-api-hook branch June 26, 2023 15:45
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

Successfully merging this pull request may close these issues.

2 participants