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

fix: focus handler typings #2152

Merged
merged 1 commit into from
Apr 24, 2021
Merged

fix: focus handler typings #2152

merged 1 commit into from
Apr 24, 2021

Conversation

fmauquie
Copy link
Contributor

Typings did not allow passing a function taking setFocused to addEventListener

Fixing by using the same typings as in onlineManager.ts, tweaked to allow default Window.Event behavior

This allows setting the React Native focus handler like this:

focusManager.setEventListener((setFocused) => {
  const listener = (status: AppStateStatus) => setFocused(status === "active");
  AppState.addEventListener("change", listener);
  return () => AppState.removeEventListener("change", listener);
});

@vercel
Copy link

vercel bot commented Apr 20, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/DA9uSh5rPfaZixNpx7GY6QcRMsVy
✅ Preview: https://react-query-git-fork-fmauquie-patch-1-tannerlinsley.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 20, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0a408e7:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 20, 2021

seems like I fixed this for the onlineManager here: https://github.com/tannerlinsley/react-query/pull/2053/files

but forgot about this one 🤦

@fmauquie
Copy link
Contributor Author

Your approach is slightly different, it better captures the intention of the method IMO. I'm modifying my commit to match.

Typings did not allow passing a function taking `setFocused` to addEventListener

Fixing by using the same typings as in `onlineManager.ts`, same behavior as set in TanStack#2053
@tannerlinsley
Copy link
Collaborator

🎉 This PR is included in version 3.13.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants