如何在spfx中以黑白方式发送父/子数据

问题描述 投票:0回答:1

我有一个父组件,我想将数据发送到它的子组件。

我尝试使用传递数据的react方法,但出现错误。

错误:

Type'{pdata:number; }'不能分配给'IntrinsicAttributes&IntrinsicClassAttributes&Readonly 和只读'。属性'pdata'在类型'IntrinsicAttributes&IntrinsicClassAttributes&Readonly 和只读'。

下面是代码

父文件:

<Modern pdata={this.state.length} />

子文件:

import * as React from 'react';
export default class Modern extends React.Component {
constructor(props){
super(props);

}

render() {
    return (
        <div>
<p>Hello  Modern {this.props.pdata}</p>
        </div>
    )
}
}
reactjs sharepoint spfx
1个回答
0
投票

反应是spfx使用typescript。所以您需要为道具创建一个界面。

interface ModernProps {
pdata: number;
}

export default class Modern extends React.Component<ModernProps>
© www.soinside.com 2019 - 2024. All rights reserved.