React-spring useTransitions Error no typescript

Asked

Viewed 72 times

1

I’m having a problem, replicating a code I saw on the net, but he’s giving me a typo on Typescript. The code is exactly the same, but is returning me error in typing Props and I can’t seem to fix it.

The error is as follows:

Object literal may only specify known properties, and 'from' does not exist in type 'any[]'. TS2345

I tried to look for the typefaces of the package the part to try to solve, but I did not find anything.

If anyone can help me, I’d be very grateful.

const ToastContainer: React.FC<ToastContainerProps> = ({ messages }) => {
  const ref = useRef();
  const messagesWithTransitions = useTransition(
    messages,
    (message: ToastMessage) => message.id,
    {
      from: { right: '-120%' },
      enter: { right: '0%' },
      leave: { right: '-120%' },
    },
  );

  return (
    <Container>
      {messagesWithTransitions.map(({ item, key, props }) => (
        <Toast key={key} message={item} />
      ))}
    </Container>
  );
};
  • Show the types ToastContainerProps and ToastMessage.

  • The error will disappear if you remove (message: ToastMessage) => message.id,

  • Guys, I was able to resolve returning an earlier version of React Spring, but I found it very strange. I had tried the method of removing the key, (message: ToastMessage) => message.id but to no avail.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.