简体   繁体   English

外部 React 组件未在 App.js 中呈现

[英]External React components are not rendering in App.js

I am very new to react.js.我对 react.js 很陌生。 When I was working on a practice project, I encountered this strange error.我在做一个练习项目的时候,遇到了这个奇怪的错误。 Some components from an external js file render when imported and some do not.来自外部 js 文件的某些组件在导入时会呈现,而有些则不会。

app.js:应用程序.js:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Hello from './components/hello'
import functionalClick from './components/fuctionalClick'

class App extends Component {
  render() {
    return (
      <div className="App">

        <Hello name='Lol   '></Hello>

        <functionalClick></functionalClick>
      </div>
    );
  }
}

export default App;

functionalClick.js:功能性Click.js:

import React from 'react'

function fuctionalClick() {
    return (
        <div>
            <button>Click</button>
        </div>
    )
}

export default fuctionalClick

hello.js:你好.js:

import React from 'react';
const Hello = (props) => {
    return (
        <div>
            <h1>
                Hello {props.name}!
            </h1>
        </div>
    );
}

export default Hello;

The functionalClick.js does not render But the first method does(hello.js).功能性Click.js 不呈现但第一种方法可以(hello.js)。 Even when the syntax i followed, was almost same.即使我遵循的语法也几乎相同。 enter image description here在此处输入图片说明

As per the docs User-Defined Components Must Be Capitalized根据文档用户定义的组件必须大写

React also shows some warnings when you try to use not HTML tags in lowercase.当您尝试使用非小写的 HTML 标签时,React 也会显示一些警告。

Warning: is using uppercase HTML.警告:正在使用大写的 HTML。 Always use lowercase HTML tags in React.在 React 中始终使用小写的 HTML 标签。

Warning: The tag is unrecognized in this browser.警告:此浏览器无法识别该标签。 If you meant to render a React component, start its name with an uppercase letter.如果您打算渲染 React 组件,请以大写字母开头。

Check the warnings here: https://codesandbox.io/s/react-example-exw9h检查这里的警告: https : //codesandbox.io/s/react-example-exw9h

I think you might have a typo in the declaration of the function fuctionalClick .我认为您在函数fuctionalClick的声明中可能有错字。 Looks like you're missing an n after the c .看起来你在c之后缺少一个n Your Component might be imported as undefined .您的 Component 可能被导入为undefined Check your browser console for other info.检查您的浏览器控制台以获取其他信息。

Try changing this:尝试改变这个:

import functionalClick from './components/fuctionalClick'

and this:和这个:

<functionalClick></functionalClick>

To this:对此:

import fuctionalClick from './components/fuctionalClick'

and this:和这个:

<fuctionalClick></fuctionalClick>

And see if that helps.看看这是否有帮助。

In your question typo mistakes but sometimes also not work then check your components name first later.在您的问题中,错字错误但有时也不起作用,然后先检查您的组件名称。 if it is small then do it capital.如果它很小,那就做资本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM