Add ref prop instead of hooks
See original GitHub issueIssue Description
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:
- Created 3 years ago
- Reactions:2
- Comments:15 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hope that @compulim will read that.
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.