javascript - src\components\Home.js Line 6:10: 'Container' is not defined react/jsx-no-undef
问题描述
import React from 'react'
import styled from "styled-components";
function Home() {
return (
<Container>
home
</Container>
)
}
export default Home
错误来了
src\components\Home.js Line 6:10: 'Container' is not defined react/jsx-no-undef
解决方案
您需要先定义容器,例如:
import React from 'react'
import styled from "styled-components";
const Container = styled.Text`
font-size: 42;
`;
function Home() {
return (
<Container>
home
</Container>
)
}
export default Home
如果您有一个Container
已经创建并导出的默认值,则按如下方式导入它
import React from 'react'
import styled from "styled-components";
import Container from "file-path";
function Home() {
return (
<Container>
home
</Container>
)
}
export default Home
如果将 Container 导出为常量,则需要导入为
import React from 'react'
import styled from "styled-components";
import { Container } from "file-path";
function Home() {
return (
<Container>
home
</Container>
)
}
export default Home
推荐阅读
- go - 为什么 Go 根据我声明缓冲区的位置设置不同的内容类型
- git - 可以将 Visual Studio 设置为在我去编辑文件时自动使文件可写吗?
- c - 如何在 x86-64 上将 80 位长 double 的尾数作为 int
- r - 根据 R 中两个表的信息构建稀疏表
- css - 强制图像具有相同的形状,但仍保持响应
- python - np.mean 的 Numba 失败
- javascript - 在tippy.js工具提示中延迟加载图像?
- python - 如何在 Python 中查找对象的所有属性的类型?
- youtube-iframe-api - cc_load_policy=1 不适用于只有自动生成的字幕的视频
- ruby-on-rails - 扩展 Rails 主动存储