我有这两个组成部分:

BasicMaintainer

// etc...
import GeneratingUnit from "./generating-unit";

class BasicMaintainer extends Component {
  constructor(props) {
    super(props);
    // etc...
  }

  // etc...

  handleOnSelectFile = event => {
    here I want to use: GeneratingUnit.columns.length
  }


其他组件GeneratingUnit是:

import React from 'react';
//...code

export const columns = [
    {name: 'ID', numeric: false, disablePadding: true, key: 'id'},
    {name: 'NOMBRE', numeric: false, disablePadding: true, key: 'nombre'},
    {name: 'DESCRIPCIÓN', numeric: false, disablePadding: true, key: 'descripcion'},
    {name: 'IT UNIDAD GENERADORA', numeric: false, disablePadding: true, key: 'it_unidad_generadora'},
]

const GeneratingUnit = props => <div>
    //code...
</div>

export default GeneratingUnit;


如何在const columns组件的handleOnSelectFile中使用BasicMaintainer

最佳答案

将其导入您的BasicMaintainer文件:

import GeneratingUnit, {columns} from "./generating-unit";

关于javascript - react ,从另一个组件读取const,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59665432/

10-12 12:35