Answer the question
In order to leave comments, you need to log in
css transition not working correctly in React, what could be wrong?
Can you please tell me why react kills transition animations if the keys of the elements in the array do not change?
At the same time, he does not touch the animation in one direction.
In my example, the animation works out if you press the left button. But on the right button the animation doesn't work as I expect.
Example in sand https://codesandbox.io/embed/flamboyant-kirch-49uc...
Answer the question
In order to leave comments, you need to log in
It is not clear how to fork there, so here is the corrected code
import React, { useMemo } from "react";
import * as S from "./dots.style";
function makeData(dots, shift, width) {
const normShift = shift >= 0 ? shift : shift - dots.length * shift;
return dots.map((dot, index) => ({
key: dot,
isFirst: index === 0,
isLast: index === dots.length - 1,
left: ((normShift + index) % dots.length) * width
}));
}
export const Dots = ({ dots, shift }) => {
const data = useMemo(() => makeData(dots, shift, 25), [dots, shift]);
return (
<S.Container>
{data.map(({ key, left, children }) => (
<S.Dot key={key} left={left}>
{key}
</S.Dot>
))}
</S.Container>
);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question