简体   繁体   English

如何将一个js文件中定义的方法用于react项目中的另一个js文件

[英]How to use methods defined in one js file to the other js file in react project

My problem is, I have a js file having a functionality of opening a tab-bar on clicking.我的问题是,我有一个 js 文件,它具有在点击时打开标签栏的功能。 I want the same feature of opening a tab-bar to be used in the other js file as well without adding the methods and functionalities again in that js file.我希望在另一个 js 文件中也可以使用打开标签栏的相同功能,而无需在该 js 文件中再次添加方法和功能。 How could this be done?怎么可能做到这一点?

I have used the method openPane() in this js file, it shows the error that I haven't defined the openPane().我在这个js文件中使用了openPane()方法,它显示我没有定义openPane()的错误。 In order to define I have to include all the other related methods, libraries to this all well, which is not the best way.为了定义,我必须包含所有其他相关的方法、库,这一切都很好,这不是最好的方法。 What would be the recommended way of using entire functionality without defining in the particular file.在不定义特定文件的情况下使用整个功能的推荐方法是什么。

This is the file where the adding tab is being defined https://jsfiddle.net/6719phr3/1/这是定义添加选项卡的文件https://jsfiddle.net/6719phr3/1/

So I want to add a tabbar on clicking Cumulative Data Rate in the below give code.所以我想在下面的代码中单击累积数据速率时添加一个标签栏。

import React, { useState,useCallback } from "react";
import {Card,CardGroup,Badge} from 'react-bootstrap';
 
const Health_status = (props) => {
 return (
<CardGroup>
  <Card className="cards">
    
    <Card.Body>
      <Card.Title>Cluster-1 [ID]</Card.Title>
      <Card.Text>
      
      </Card.Text>
    </Card.Body>
    
      <Card border="secondary" style={{ width: '18rem' }} className ="sub-cards-rec">
      <Card.Header>Recording Unit [ID]</Card.Header>
      <Card.Body>
        <Card.Title>[ID]</Card.Title>
        <Card.Text>
          <h6 onClick{()=>openPane()}><Badge pill bg="primary" >Cumulative Data Rate:{}</Badge></h6>
          
        {css ? (<h6 onClick={toggle2}><Badge pill bg="success" >Cumulative Sensor Status:{}</Badge></h6>)
          :(<h6 onClick={toggle2}><Badge pill bg="danger" >Cumulative Sensor Status:{}</Badge></h6>)
          }
        </Card.Text>
      </Card.Body>
      </Card><br />
      <Card border="secondary" style={{ width: '18rem' }} className ="sub-cards-ana">
      <Card.Header>Analysis Unit [ID]</Card.Header>
      <Card.Body>
        <Card.Title>[ID]</Card.Title>
        <Card.Text>
        <h6><Badge pill bg="warning" >Instance-Number:{}</Badge></h6>
        </Card.Text>
      </Card.Body>
      </Card><br />
  </Card>
  </CardGroup>

  }
  export default Health_status;

You can export multiple module您可以导出多个模块

 export default Health_status;
 export  your_function;

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

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