TypeScript compliant Ref handling for animating the movement of arrows
See original GitHub issueIn trying to achieve animation of arrows on div scrolling, I ran into a couple of issues. I achieved this:
But through some scullduggery.
I extended the ArcherContainerProps interface to contain:
ref?: any
forceUpdate?: () => void
So that I could grab the reference to the archer container and also forceUpdate the component (not sure why I couldn’t access these generic react props?)
Then I attached the event listeners to my divs and on scroll I forceUpdate the component.
export default class Space extends Component<Props, State> {
state = {
currentSelectionIdx: 0,
}
baseSpaceRef = React.createRef<HTMLDivElement>()
linkSpaceRef = React.createRef<HTMLDivElement>()
archerContainerRef = React.createRef<ArcherContainerProps>()
componentDidMount = () => {
this.baseSpaceRef.current &&
this.baseSpaceRef.current.addEventListener('scroll', this.isScrolling)
this.linkSpaceRef.current &&
this.linkSpaceRef.current.addEventListener('scroll', this.isScrolling)
}
componentWillUnmount = () => {
this.baseSpaceRef.current &&
this.baseSpaceRef.current.removeEventListener('scroll', this.isScrolling)
this.linkSpaceRef.current &&
this.linkSpaceRef.current.removeEventListener('scroll', this.isScrolling)
}
isScrolling = () => {
this.archerContainerRef!.current!.forceUpdate()
}
render() {
return (
<div>
<ArcherContainer ref={this.archerContainerRef}>
<div className="space">
<div className="baseSpace" ref={this.baseSpaceRef}>
{this.baseCards()}
</div>
<div className="linkedSpace" ref={this.linkSpaceRef}>
{this.linkedCards()}
</div>
</div>
</ArcherContainer>
</div>
)
}
}
It feels hacky though.
I was wondering if you could supply the typescript compliant functionality? It may not need a new feature, just I haven’t found it yet.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How To Use Framer Motion With React, TypeScript and Styled ...
To prepare the animation we have to use the animate property. It should be added to the motion component (in this case it...
Read more >How can I animate a react.js component onclick and detect the ...
I want to have a react component flip over when a user clicks on the DOM element. I see some documentation about their...
Read more >Total Guide To Dynamic Angular Animations That Can Be ...
Angular animations are usually implemented using a declarative approach. We reference animations in a component's template using ...
Read more >Blog | Remotion | Make videos programmatically in React
This package offers utilities for animating and manipulating SVG paths! With 9 pure, type-safe functions, we cover many common needs while ...
Read more >react-beautiful-dnd-next - npm
This is to maximise performance by allowing the GPU to handle the movement. The CSS animation curve has been designed to communicate getting...
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 FreeTop 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
Top GitHub Comments
@pierpo Thanks, works like a charm! Really appreciate the quick response 💯
@pierpo seems to!
Thanks!!