方法参数:解构+保存原始参数(ReactJS组件)

Seb*_*ber 9 javascript destructuring ecmascript-6 reactjs

有没有办法实现方法参数解构,但也能得到方法参数.

在具有无状态组件的React应用程序的上下文中,我希望能够替换

const MyComponent = (props) => {
  const {prop1, prop2} = props;
  return (
    <div className={prop1 + '-' + prop2}>
      <Child {...props}/>
    </div>
  ) 
}
Run Code Online (Sandbox Code Playgroud)

用更简洁的语法

const MyComponent = (props: {prop1, prop2}) (
  <div className={prop1 + '-' + prop2}>
    <Child {...props}/>
  </div>
) 
Run Code Online (Sandbox Code Playgroud)

有没有这样的语法?

Yad*_*ran 2

我们有这个:

const MyComponent = ({ prop1, prop2, ...rest }) (
  <div className={prop1 + '-' + prop2}>
    <Child prop1={prop1} prop2={prop2} {...rest} />
  </div>
) 
Run Code Online (Sandbox Code Playgroud)