[英]Attempted import error: 'styles' is not exported from './styles'
I am trying to import styles from style.js
file and the that file contains below code我正在尝试从style.js
文件中导入 styles 并且该文件包含以下代码
const export styles = {
border: 'solid',
textAlign : 'center',
boxShadow : '2px 2px'
}
But it shows the below error in that file但它在该文件中显示以下错误
'export' is not allowed as a variable declaration name.
But when I add the export
keyword as shown below code但是当我添加export
关键字时,如下代码所示
const styles = {
border: 'solid',
textAlign : 'center',
boxShadow : '2px 2px'
}
export default styles;
And trying to import in my component as并尝试将我的组件导入为
import * as styles from "./styles";
<div style={styles.styles}>
Style
</div>
I am getting the below error我收到以下错误
Attempted import error: 'styles' is not exported from './styles'.
How do I resolve it?我该如何解决?
Use this way style.js
使用这种方式style.js
import { StyleSheet } from 'react-native';
export const styles = StyleSheet.create({
});
And trying to import in my component as并尝试将我的组件导入为
import styles from "./styles";
Try export as default尝试默认导出
const styles = {
border: 'solid',
textAlign : 'center',
boxShadow : '2px 2px'
}
export default styles;
I tried the below code it worked for me我尝试了下面对我有用的代码
export const externalStyles = {
color : 'red',
backgroundColor: 'green'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.