首页 > 解决方案 > 如何将道具从无状态功能组件传递到类组件?

问题描述

我有一个父功能组件:

function testing() {
  const columns = [{ name: 'test1' },{ name: 'test2' }];
  const data = [{ data: 'data1' }];

  return (
    <Table columns={columns} data={data} title='Test' />
  )
}

调用子类组件:

class Table extends React.Component {
  render() {
    const columns = this.props.columns;
    const data = this.props.data;
    const title = this.props.title;
  }
}

现在this.props是空对象。

在这种情况下如何访问道具?

标签: javascriptreactjs

解决方案


推荐阅读