web icon indicating copy to clipboard operation
web copied to clipboard

feat: add useStateRef hook

Open michaltarasiuk opened this issue 3 years ago • 3 comments

Hook description

One rudimentary way to measure the position or size of a DOM node is to use a callback ref. React will call that callback whenever the ref gets attached to a different node.

Note that we pass [] as a dependency array to useCallback. This ensures that our ref callback doesn’t change between the re-renders, and so React won’t call it unnecessarily, so in current example the callback ref will be called only when the component mounts and unmount. As in result we will not fall into infinite re-renders.

Checklist

  • [X] Have you read the contribution guidelines?
  • [ ] If you are porting a hook from react-use, have you checked #33 and the migration guide to confirm that the hook has been approved for porting?
  • [ ] Does the code have comments in hard-to-understand areas?
  • [ ] Is there an existing issue for this PR?
    • link issue here
  • [X] Have the files been linted and formatted?
  • [X] Have the docs been updated?
  • [X] Have you written tests for the new hook?
  • [X] Have you run the tests locally to confirm they pass?

michaltarasiuk avatar Jan 28 '23 18:01 michaltarasiuk

Codecov Report

Merging #1113 (f833f4a) into master (f6829c0) will increase coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1113      +/-   ##
==========================================
+ Coverage   98.52%   98.53%   +0.01%     
==========================================
  Files          63       64       +1     
  Lines        1082     1091       +9     
  Branches      180      180              
==========================================
+ Hits         1066     1075       +9     
  Misses          2        2              
  Partials       14       14              
Impacted Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)
src/useStateRef/index.ts 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Jan 28 '23 18:01 codecov[bot]

So, you've

  • added new dependency (not compatible with our testing pipeline
  • globally disabled linting rule without any reasoning
  • once again ignored PR guidelines

Last one is somehow "forgivable"

But first two are no-go since they should be separate pull requests with reasoning

xobotyi avatar Jan 28 '23 19:01 xobotyi

Hi @xobotyi, in days I will create a pull request for two first points.

michaltarasiuk avatar Jan 28 '23 20:01 michaltarasiuk