![](/img/trans.png)
[英]How to import the component in another component which include image in react js
[英]Import an include file in react component and acess the imports
我正在開發一個 React Native 應用程序,並且有一個如下所示的組件:
import React, { Component } from 'react';
import './OtherImports';
class Products extends Component {
}
現在在另一個名為 OtherImports.js 的文件中,我想導入其他依賴項/模塊,以便我可以在我的所有組件中重用它們。
在 OtherImports.js 中
window.navigator.userAgent = 'react-native';
import io from 'socket.io-client/dist/socket.io';
現在,當我在組件中包含(導入)此文件時,出現錯誤。
我怎樣才能在反應組件中包含這個文件,但又能夠使用它們? 例如我例子中的變量io
您正在嘗試執行的操作(基於評論)您嘗試使用自定義文件導入導入socket.io
此處您必須添加到文件中以使其工作:
OtherImports.js
window.navigator.userAgent = 'react-native';
import io from 'socket.io-client/dist/socket.io';
export io;
你可以使用export default
注意:您可以做的是直接在您使用它的代碼中導入它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.