[英]Why won't my Index.js file be recognized?
我制作了一個單獨的Index.js
文件,以容納要在整個正在創建的應用程序中導出的所有組件。 我以為我要使用的文件路徑是正確的,但是...
我收到一條錯誤消息:
無法解決
'/ User / user / projects / Something / src / components / components'作為文件
也不作為文件夾(空)
我怎樣才能解決這個問題?
這是LoginForm.js
:
import React, { Component } from 'react';
import { TouchableOpacity, StyleSheet, View, Text ,Button } from 'react-native';
import { UserInput } from './components';
class LoginForm extends Component {
render() {
return(
<View style={styles.container}>
<UserInput/>
<TouchableOpacity style={styles.button}>
<Button
title="Press Me"
/>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingHorizontal: 10
},
button: {
alignItems: 'center',
backgroundColor: '#DDDDDD',
padding: 10
}
});
export default LoginForm;
這是Index.js
:
export * from './UserInput';
export * from './LoginForm';
在LoginForm.js
的當前工作目錄中,沒有components
文件夾。 從腳本中,您需要LoginForm
組件中的UserInput
組件。
你可以簡單地做到
import { UserInput } from './UserInput';
當您要在其他目錄的組件目錄中導入文件夾的選定組件時,正確使用components
文件夾的index.js
更新:
在LoginForm
組件中
import UserInput from './UserInput'; //default export
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.