我看到了许多关于如何将道具从一个块组件传递到另一个组件的示例,但它们都使用ES5语法。
在ES6中,注册块时的编辑功能如下所示:
edit( { attributes, className, setAttributes } ) {
const { title, url, image, content } = attributes;
...etc
我想传递属性和setAttributes
到组件。这个语法正确吗?<MyComponent { ...{setAttributes, ...attributes } } />
那么在我的组件中,我是否可以这样访问它们:?class MyComponent extends Component {
constructor( props ) {
super( ...arguments )
}
render() {
const { title, url, image, content } = this.props.attributes;
const { setAttributes } = this.props;
...etc
有很多方法可以做到这一点,但不确定推荐哪种方法。