4

While using material ui, I realized they have a prop called in in the transitions components, but when trying to destruct the props, I can't because in is a reserved key word.

const MyFade = ({ children, in, ...otherProps }) => { // this gives me an error 
  return (
    <div {...otherProps}>
      <Fade in={in}>{children}</Fade>
    </div>
  );
};

How can I do this? I need to destruct in and have otherProps to spread in the div.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Vencovsky
  • 28,550
  • 17
  • 109
  • 176

1 Answers1

5

Just assign a new, not reserved name inside destructuring.

const o = {
   in: 'foo',
   out: 'boo',
};

const { in: inProp } = o;
      // ^^^^ assign new name

console.log(inProp);
kind user
  • 40,029
  • 7
  • 67
  • 77