Skip to content

How to prevent re-rendering when <Timeline /> playState changes? #36

Open
@capi1O

Description

@capi1O

I have defined my timeline as such:

const Component = () => {

const [playState, setPlayState] = useState(PlayState.pause);

return (
		<Timeline
			playState={playState}
			labels={[{ label: 'start', position: 0 }]}
			target={<Content />}
		>
			<Tweens />
		</Timeline>
);

where <Content /> is a component using react-gsap targets.set to set targets similarly to what is done in the examples.

I want to control my timeline playState using useState inside my <Component /> which contains the <Timeline />.

But every time I change state <Content /> is re-rendered of course. The thing is my playState depends depends on <Content /> (I wait for some elements inside <Content /> to load, then I inform <Component /> that animation can begin and setPlayState(PlayState.play). Because of the re-rendering it is not possible because <Content /> stuff are reloaded, the animation begins before it has fully loaded.

I don't think this is currently possible due how react-gsap is structured because content is a rendered prop of <Timeline />. I understand this was done this way in order to be able to set the targets but IMO we should be able to separate content and animation in the React tree.

I tried to make it clear and I hope I am not doing anything too weird.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions