React-Native:元素类型无效
React-Native: Element type is invalid
我对 nativebase 页脚有疑问
我有容器,如果我包含 MyFooter,它会给我这个错误:
元素类型无效:应为字符串(对于内置组件)或 class/function(对于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件。
// main.js
import MyFooter from './MyFooter';
...
<Container>
<MyHeader title="Оплаты" />
<Content></Content>
<MyFooter />
</Container>
和页脚组件
// MyFooter.js
const MyFooter = props => {
return (
<Footer>
<FooterTab>
<Button vertical active>
<Text>Info</Text>
</Button>
<Button vertical >
<Text>Remove</Text>
</Button>
</FooterTab>
</Footer>
);
}
export default MyFooter;
但是如果我像这样更改 MyFooter 的渲染方法:
// MyFooter.js
return (
<View>
<Text>
Test
</Text>
</View>
)
所以问题不在 export/import 中,因为在 MyFooter 中使用另一个渲染器一切正常。
有人可以帮忙吗?
答案 - 从'react-native'导入{文本、页脚、页脚标签、按钮、图标}; ('react-native' 而不是 'native-base')
这是您的 MyFooter
组件吗?首先尝试导出您的组件 export default MyFooter
,如下所示:
const MyFooter = () => (
<Footer>
<FooterTab>
<Button vertical active>
<Icon name="information" />
<Text>Инфо</Text>
</Button>
<Button vertical >
<Icon name="add" />
<Text>Оплаты</Text>
</Button>
<Button vertical >
<Icon name="remove" />
<Text>Снятия</Text>
</Button>
</FooterTab>
</Footer>
);
export default MyFooter;
如果您完全按原样粘贴代码,那么您在 MyFooter.js
中的 return 语句后缺少右大括号
我对 nativebase 页脚有疑问 我有容器,如果我包含 MyFooter,它会给我这个错误: 元素类型无效:应为字符串(对于内置组件)或 class/function(对于复合组件)但得到:未定义。您可能忘记从定义组件的文件中导出组件。
// main.js
import MyFooter from './MyFooter';
...
<Container>
<MyHeader title="Оплаты" />
<Content></Content>
<MyFooter />
</Container>
和页脚组件
// MyFooter.js
const MyFooter = props => {
return (
<Footer>
<FooterTab>
<Button vertical active>
<Text>Info</Text>
</Button>
<Button vertical >
<Text>Remove</Text>
</Button>
</FooterTab>
</Footer>
);
}
export default MyFooter;
但是如果我像这样更改 MyFooter 的渲染方法:
// MyFooter.js
return (
<View>
<Text>
Test
</Text>
</View>
)
所以问题不在 export/import 中,因为在 MyFooter 中使用另一个渲染器一切正常。 有人可以帮忙吗?
答案 - 从'react-native'导入{文本、页脚、页脚标签、按钮、图标}; ('react-native' 而不是 'native-base')
这是您的 MyFooter
组件吗?首先尝试导出您的组件 export default MyFooter
,如下所示:
const MyFooter = () => (
<Footer>
<FooterTab>
<Button vertical active>
<Icon name="information" />
<Text>Инфо</Text>
</Button>
<Button vertical >
<Icon name="add" />
<Text>Оплаты</Text>
</Button>
<Button vertical >
<Icon name="remove" />
<Text>Снятия</Text>
</Button>
</FooterTab>
</Footer>
);
export default MyFooter;
如果您完全按原样粘贴代码,那么您在 MyFooter.js
中的 return 语句后缺少右大括号