【问题标题】:How to call/access React.FC from other file - Typescript如何从其他文件调用/访问 React.FC - Typescript
【发布时间】:2021-07-21 13:12:12
【问题描述】:

代码-

const Exne: React.FC <IProps> = ({x}) => 
    {
    console.log('input', x);    
    const [getx, assignx] = useState(x);
    console.log(getx, assignx);
    return(getx)
    };

在这段代码中,如何从其他文件访问或调用Exne

谢谢

【问题讨论】:

标签: reactjs typescript


【解决方案1】:

您可以导出 const 并将其导入到您要使用的另一个文件中。

file.ts:

export const Exne: React.FC <IProps> = ({x}) => {
    console.log('input', x);    
    const [getx, assignx] = useState(x);
    console.log(getx, assignx);
    return(getx)
};

another.ts:

import { Exne } from './file';

// and you can use Exne as you are in file.ts

【讨论】:

    猜你喜欢
    • 2020-01-18
    • 2020-11-28
    • 2017-09-15
    • 1970-01-01
    • 2021-11-28
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多