什么是...做这个阵营(使用JSX)代码,什么是它叫什么名字?
<Modal {...this.props} title='Modal heading' animation={false}>
Run Code Online (Sandbox Code Playgroud) 我对ES2015中的spread语法和rest参数感到困惑.任何人都能用适当的例子来解释它们之间的区别吗?
我试图理解React的高阶组件的结构,但是所有资源仅假设您在编写时已经了解了扩展运算符在高阶组件中的用途:BaseComponent {... this.props} {。 ..this.state}。如果某个组件已经作为道具传入,为什么必须像这样散布道具?
import React, { Component } from 'react';
const EnhanceComponent = BaseComponent => {
return class EnhancedComponent extends Component {
state = {
name: 'You have been enhanced'
}
render() {
return (
<BaseComponent {...this.props} {...this.state} />
)
}
}
};
export default EnhanceComponent;
Run Code Online (Sandbox Code Playgroud) 我在React应用程序中注意到以下内容:
<UserList
{...{ userIdsTyping, users }}
/>
Run Code Online (Sandbox Code Playgroud)
到底在{...{ userIdsTyping, users }}做什么?我知道它将子节点传递给UserList组件,但是传播运算符如何在这里工作?它有什么作用userIdsTyping和users?