Simpler hook-only API without rendering a component?
See original GitHub issueIssue: 🚀 Feature Proposal
Thank you for this amazing animation library!
I’ve been wondering if there’s any way for the animated component to be avoided at all by passing the ref directly to useSpring(s)
. As far as I understand, the animated component is used only so that there is access to the ref (to directly set styles) and otherwise props are just passed down, but maybe I’m missing something here.
Motivation
We’d like to create a hook that would contain useSpring
that has access to the ref.
Example
What I’m proposing would be this:
const ref = useRef();
useSpring( { opacity: ..., target: ref } );
return <div ref={ ref } { ...otherProps } />;
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ReactJS: how to call useEffect hook only once to fetch API data
So to execute the code only during initial render/component mount you can pass an empty array which means no dependencies specified when the ......
Read more >Fetching Data and Updating State with React Hooks - Pluralsight
A previous guide covered how to fetch data from a REST API and how to re-render a React component with the results. The...
Read more >Run useEffect Only Once - CSS-Tricks
useEffect will run when the component renders, which might be more ... is that if you're doing something like fetching data from an...
Read more >Learn React Hooks – A Beginner's Guide - freeCodeCamp
Before React version 16.8 was introduced, functional components were ... and we only used them for rendering very simple components to the.
Read more >Hooks API Reference - React
They let you use state and other React features without writing a class. ... Note that React may still need to render that...
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
FWIW, you can do something similar already (with v9):
You could make a custom hook to avoid duplication:
edit: Oh wait, I forgot that
applyAnimatedValues
is not inGlobals
anymore. 😅 We should probably export it for each platform.closing due to inactivity. please use discussions or discord if you want more help or please consider creating a PR if you want to add a feature 😄