|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | import { useRef } from 'react';
|
|---|
| 2 | import { uniqueId } from './DataUtils';
|
|---|
| 3 |
|
|---|
| 4 | /**
|
|---|
| 5 | * This hook returns a unique animation id for the object input.
|
|---|
| 6 | * If input changes (as in, reference equality is different), the animation id will change.
|
|---|
| 7 | * If input does not change, the animation id will not change.
|
|---|
| 8 | *
|
|---|
| 9 | * This is useful for animations. The Animate component
|
|---|
| 10 | * does have a `shouldReAnimate` prop but that doesn't seem to be doing what the name implies.
|
|---|
| 11 | * Also, we don't always want to re-animate on every render;
|
|---|
| 12 | * we only want to re-animate when the input changes. Not the internal state (e.g. `isAnimating`).
|
|---|
| 13 | *
|
|---|
| 14 | * @param input The object to check for changes. Uses reference equality (=== operator)
|
|---|
| 15 | * @param prefix Optional prefix to use for the animation id
|
|---|
| 16 | * @returns A unique animation id
|
|---|
| 17 | */
|
|---|
| 18 | export function useAnimationId(input) {
|
|---|
| 19 | var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'animation-';
|
|---|
| 20 | var animationId = useRef(uniqueId(prefix));
|
|---|
| 21 | var prevProps = useRef(input);
|
|---|
| 22 | if (prevProps.current !== input) {
|
|---|
| 23 | animationId.current = uniqueId(prefix);
|
|---|
| 24 | prevProps.current = input;
|
|---|
| 25 | }
|
|---|
| 26 | return animationId.current;
|
|---|
| 27 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.