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.

useAnimate question, not a bug

See original GitHub issue

Hi,

Simple question regarding the useAnimate hook. I was making a slider that is controlled by a prop and before I simply used that prop to revert the animation I was trying something like this:


const { play, style } = useAnimate({
        start: { transform: `translateY(${showContent ? '100%' : '0%'})`},
        end: { transform:`translateY(${showContent ? '0': '100%'})` },
    });
useEffect(() => {
        play(true);
    }, [show]);

My question is more of a curiosity, but why doesn’t the first implementation work like expected? Is it a misunderstanding of how the useEffect hook works?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hthiefcommented, Sep 9, 2019

oh! i see now what you meant about the previous question about showContent, show was the original prop name but I changed it when copying it to the comments here, and made an entirely different issue. The show content would never change and play would never get called, my bad.

😓I really should have linked an example repo from the start instead: https://codesandbox.io/embed/blazing-currying-qf9zz

in the example the first box is using the non-working impl, while the second uses the hooks.

sorry about the confusion 😬

1reaction
bluebill1049commented, Sep 6, 2019

I think this is the right solution which you posted:

const { play, style } = useAnimate({
        start: { transform: 'translateY(100%)' },
        end: { transform: 'translateY(0%)' },
    });

    useEffect(() => {
        play(showContent);
    }, [showContent]);

i haven’t test it, but look at this example, your animation probably would stay the same, because RSA wouldn’t be able to change the style because play is not been called

const { play, style } = useAnimate({
        start: { transform: `translateY(${showContent ? '100%' : '0%'})`},
        end: { transform:`translateY(${showContent ? '0': '100%'})` },
    });
useEffect(() => {
        play(true);
    }, [show]);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Actions are not set when calling useAnimations #377 - GitHub
Suggested solution: I see two problems here: A typescript error; A bug on the set. For the error: typescript error
Read more >
Framer Motion | Viewpoint 'useAnimation' triggers after the last ...
I've been doing a recommended way to do it, but only with one element. When I add more elements, animations will only trigger...
Read more >
Animate CC drawing bug for Windows 10 Tablet PC users.
Solved: This issue is NOT solved Animate CC has a serious bug pertaining to all Tablet PC devices using Windows 10, whenever you...
Read more >
Bug - Following a Target isn't working under Animator if ...
I am facing a very strange problem. ... Bug Following a Target isn't working under Animator if "Animate Physics" option is enabled.
Read more >
Why would anyone choose to use Animate Pro? - Moho Forum
AS just isn't designed to optimize a frame-by-frame workflow, ... Anyway, to answer the OP's question, "Why would anyone choose Animate Pro?
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