question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ref prop instead of hooks

See original GitHub issue

It would be much easier if instead of using hooks like useScrollToBottom just add a ref prop and add all the methods inside. What I mean:

const App = () => {
   const scrollRef = useRef();

   const scroll = () => {
     scrollRef.current.scrollToBottom()
     //and all other hooks like useSticky
     if(scrollRef.current.isSticky()) console.log('is sticky')
   }
   return (
        <ScrollToBottom mode="bottom" ref={scrollRef}>
             <button onClick={scroll}>
                  Scroll
              </button>
              <Content />
        </ScrollToBottom>
   )
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
yo-pngcommented, Aug 6, 2020

Hope that @compulim will read that.

1reaction
compulimcommented, Aug 7, 2020

Sure. In the meanwhile, please copy my code first.

The current README.md also have some typos I should fix it sooner.

Thanks for understanding. I really hope your project shine for a long time. This is the reason I created this component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Thoughtful Way To Use React's useRef() Hook
A unique way to implement a useRef hook is to use it to store values instead of DOM references. These values can either...
Read more >
Refs and the DOM - React
Refs provide a way to access DOM nodes or React elements created in the render method. In the typical React dataflow, props are...
Read more >
The Complete Guide to useRef() and Refs in React
In this post you'll learn how to use React.useRef() hook to create persisted mutable values (also known as references or refs), as well...
Read more >
A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >
React: Using Refs with the useRef Hook - Ross Bulat - Medium
The useRef hook has been implemented as a solution to use React refs within functional components.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found