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

feat: new hook useSyncedRef #42

Merged
merged 3 commits into from
May 6, 2021
Merged

feat: new hook useSyncedRef #42

merged 3 commits into from
May 6, 2021

Conversation

xobotyi
Copy link
Contributor

@xobotyi xobotyi commented May 6, 2021

What new hook does?

Like useRef, but it returns immutable ref that contains actual value.

I'm not sure about hook naming, i dont really like the useSyncedRef, but it is the best i came up with.

Checklist

  • Have you read contribution guideline?
  • Does the code have comments in hard-to-understand areas?
  • Is there an existing issue for this PR?
    • link issue here
  • Have the files been linted and formatted?
  • Have the docs been updated?
  • Have the tests been added to cover new hook?
  • Have you run the tests locally to confirm they pass?

@xobotyi xobotyi added the 🎂 new hook New hook added label May 6, 2021
@xobotyi xobotyi requested a review from JoeDuncko May 6, 2021 09:41
@codecov
Copy link

codecov bot commented May 6, 2021

Codecov Report

Merging #42 (0ac97dc) into master (6af7867) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #42   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        20    +1     
  Lines          155       163    +8     
  Branches        22        22           
=========================================
+ Hits           155       163    +8     
Impacted Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)
src/useMediatedState.ts 100.00% <100.00%> (ø)
src/useSyncedRef.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 952f35a...0ac97dc. Read the comment docs.

@JoeDuncko
Copy link
Contributor

What's an example use case for this hook? It doesn't seem like the example story illustrates one very well.

@xobotyi
Copy link
Contributor Author

xobotyi commented May 6, 2021

I'm unable to imagine different =(

@JoeDuncko
Copy link
Contributor

Do you have an example where this hook would be useful in general? I think I need help "getting" this one.

@xobotyi
Copy link
Contributor Author

xobotyi commented May 6, 2021

It is mostly required for other hooks, to provide stable API, 4ex:
https://github.com/react-hookz/web/blob/master/src/useMediatedState.ts#L21

Will be replaced with this hook.

P.s.: just realized that i wanted to write it in docs =)

Copy link
Contributor

@JoeDuncko JoeDuncko left a comment

Choose a reason for hiding this comment

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

Got it, thanks for pointing that out! Let's roll with it

@xobotyi xobotyi merged commit 49810a0 into master May 6, 2021
@xobotyi xobotyi deleted the useSyncedRef branch May 6, 2021 17:38
github-actions bot pushed a commit that referenced this pull request May 6, 2021
# [1.18.0](v1.17.0...v1.18.0) (2021-05-06)

### Features

* new hook `useSyncedRef` ([#42](#42)) ([49810a0](49810a0))
@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2021

🎉 This PR is included in version 1.18.0 🎉

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
Development

Successfully merging this pull request may close these issues.

2 participants