Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Introduce a built-in component for animations in React.
Basic example
Proposed is the inclusion of a built-in
Animation
component that would handle various types of animations effectively.Please refer to this example for a demonstration: https://codesandbox.io/p/sandbox/o1mplp
1.mov
The best part of in the above example is
show
state, theshow
state determines whether theCard
component is displayed on the page. Whenshow
is set tofalse
, the Card component performs the animation and disappears after completion.Animations can be composed together as shown in this example: https://codesandbox.io/p/sandbox/0rm9xk
2.mov
Motivation
In React projects, animations are often handled by external packages, each with their own advantages and disadvantages. Having a built-in component for animations in React would be beneficial as it can directly interact with low-level React APIs.
Detailed design
The proposed built-in Animation component would handle animations on child components by utilizing DOM access. Therefore, child components should use
forwardRef
to enable this feature. The advantage of this approach is that child components can be used with or without animation without requiring any changes.Drawbacks
Why should we not do this? Please consider:
Alternatives
For testing purposes, an alternative package called Reactima has been developed: https://www.npmjs.com/package/reactima
Adoption strategy
Introducing the proposed built-in
Animation
component would not introduce any breaking changes and would have no impact on existing React features.How we teach this
All prop and method names are based on the
Web Animation API
, which can be referenced for further guidance:https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API