简体   繁体   English

我如何在反应中使用另一个文件中的道具?

[英]How can I use the props from another file in react?

I have two files: EnhancedTableHEad and OrderDialog. 我有两个文件:EnhancedTableHEad和OrderDialog。 I need the props data from EnhancedTabledHead in my OrderDialog file. 我需要OrderDialog文件中来自EnhancedTabledHead的道具数据。 How can I achieve that ? 我该如何实现? My files look like this: 我的文件如下所示:

 //OrderDialog.jsx import EnhancedTableHead from '../../Table/EnhancedTableHead'; render() { const {classes, data, onClose, onClick, item, isSelected, rowCount, onSelectAllClick, ...other} = this.props; return () } 
 //EnhancedTableHead.jsx render() { const {onSelectAllClick, order, orderBy, numSelected, rowCount, tableConfiguration} = this.props; return () } EnhancedTableHead.propTypes = { numSelected: PropTypes.number.isRequired, onRequestSort: PropTypes.func.isRequired, order: PropTypes.string.isRequired, orderBy: PropTypes.string.isRequired, rowCount: PropTypes.number.isRequired, onChange: PropTypes.number.isRequired, }; export default EnhancedTableHead; 

Am I understaing this wrong ? 我是在坚持这个错误吗? For example, I want to use rowCount from EnhancedTableHead in my OrderDialog, but when I do console.log I get undefined. 例如,我想在OrderDialog中使用来自EnhancedTableHead的rowCount,但是当我执行console.log时,却无法定义。 If I do it inside the EnahancedTableHead, console.log will print the right value. 如果我在EnahancedTableHead中执行此操作,console.log将输出正确的值。

Spread them in OrderDialog. 将它们传播到OrderDialog中。 ie

OrderDialog.propTypes = {
 ...EnhancedTableHead.propTypes
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM