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

(react-hooks) prefer exported function instead of block-scoped variable #904

Merged
merged 2 commits into from
Jul 17, 2020
Merged

(react-hooks) prefer exported function instead of block-scoped variable #904

merged 2 commits into from
Jul 17, 2020

Conversation

dotansimha
Copy link
Contributor

@dotansimha dotansimha commented Jul 16, 2020

Summary

This PR changes the definition of React Hooks to use export function instead of export const. It's a simple change that allow developers later to interact better with the signature of the hooks.

In TS, these const are defined as block-scoped variables, and cannot be overwritten/redefined/overloaded by external TS libraries or consumers.

You can see a real-time example for that here , and it's also reported as issue

I'm working on a new plugin for https://github.com/dotansimha/graphql-code-generator , and I would like to extend urql behaviour with module augmentation - but at the moment it's not possible because of the way the hooks are defined.

Set of changes

Changed export const to be export function in all React Hooks.

@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2020

🦋 Changeset is good to go

Latest commit: 32518d7

We got this.

This PR includes changesets to release 1 package
Name Type
urql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dotansimha
Copy link
Contributor Author

@JoviDeCroock changeset seems to work fine now, thank you for fixing it :) I updated the PR.

@JoviDeCroock JoviDeCroock requested a review from kitten July 16, 2020 10:34
@JoviDeCroock JoviDeCroock merged commit 467bdbc into urql-graphql:main Jul 17, 2020
'urql': patch
---

prefer exported function instead of block-scoped variable
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
prefer exported function instead of block-scoped variable
Update hooks to be exported functions rather than exported block-scoped variables to provide TypeScript consumers with better access to their signature.

@dotansimha dotansimha deleted the prefer-function branch July 19, 2020 07:45
@dotansimha
Copy link
Contributor Author

Thanks @wgolledge @JoviDeCroock !
Any chance you plan to release a new version soon? :)

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.

3 participants