[英]React Native - unable to separate components and containers with index.js file - reexport modules
我正在重構並嘗試將組件和容器分離在單獨的目錄中。 我遵循的是Tyler McGinnis使用的模式 。
我希望能夠導入這樣的組件:
import { CardReplacement } from './Containers'
因此,我將所有組件導出到適當的index.js中。您可以在此處查看組成目錄:
我還在要在index.js文件中導出的組件中使用export default
。
但是我得到這樣的錯誤:
“意外令牌,預期{(1:7)”
有任何想法嗎? 我在React項目中使用過這種模式,並且效果很好。 在React Native中有什么可以防止這種情況發生的嗎?
在進一步調查中,我注意到這是babel錯誤,並嘗試安裝babel-preset-react-native-stage-0
但沒有解決。
您也應該可以這樣進行:
export { default as CardReplacement } from './CardReplacement/CardReplacement'
我找到了一個解決方案,但之前從未見過這種語法。
我必須先導入然后導出。 我還必須在導出周圍使用{}
:
import CardReplacement from './CardReplacement/CardReplacement' export {CardReplacement}
要簡單地使用export CardReplacement from './CardReplacement/CardReplacement
,請安裝babel-preset-react-native-stage-0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.