chenglou / chenglou/react-motion

Clarification on <Motion> 'defaultStyle'

Open
#387 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
21.9k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Specifically regarding the bolded part:

> defaultStyle?: PlainStyle
>
> Optional. The PlainStyle type maps to numbers. Defaults to an object with the same
> keys as style above, whose values are the initial numbers you're interpolating on.
> **Note that during subsequent renders, this prop is ignored. The values will
> interpolate from the current ones to the destination ones (specified by style)**.
>

The way I read that, is that if defaultStyle isn't provided, the style value will animate from the existing to the new. In the context of a counter, if we have a button that adds +10 to the count, every time we click it (without defaultStyle defined) we should be animating to the new value. 0 -> 10. 10 -> 20. and so on.

Thats not whats happening however. Removing 'defaultStyle' is completely removing the motion animation, so if Im not understanding the docs correctly, how do you do what Im trying WITHOUT keeping track of the previous value via react. If I have to keep track of it I can handle the problem, just the way I read the docs, it seemed like I didnt have to keep a reference to the previous value of the counter before the add.

And some code for reference.

```

{ counter => { Math.floor(counter.x) } }

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.