【问题标题】:src\components\Home.js Line 6:10: 'Container' is not defined react/jsx-no-undefsrc\components\Home.js Line 6:10: 'Container' is not defined react/jsx-no-undef
【发布时间】:2021-12-06 23:05:12
【问题描述】:
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

【问题讨论】:

  • 欢迎来到 SO。当涉及到asking a good question 和这个question checklist 时,您可能会发现阅读网站help section 很有用。
  • 错误是正确的。 Container 未定义。
  • 如何解决它
  • 您是否创建了Container 组件?如果您已将其导入Home
  • 请告诉我导入容器的命令是什么

标签: javascript reactjs ecmascript-2016


【解决方案1】:

你需要先定义容器例如:

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

For more please refer this

【讨论】:

    猜你喜欢
    • 2021-02-18
    • 1970-01-01
    • 2021-05-25
    • 2017-03-20
    • 2019-05-29
    • 2019-11-10
    • 2019-10-05
    • 2018-03-18
    • 2022-01-08
    相关资源
    最近更新 更多