[英]Reactjs - Imported component does not render
Made my first Reactjs App using create-react-app
.使用
create-react-app
制作了我的第一个 Reactjs 应用程序。 In my main App
component i am calling another component named menuButtons
.在我的主要
App
组件中,我调用了另一个名为menuButtons
的组件。 It is imported but it does not display.它是导入的,但不显示。
Extra info: In App.js
when press CTRL key and click on <menuButtons />
, VScode doesn't redirects me to menuButtons component.额外信息:在
App.js
,当按下 CTRL 键并单击<menuButtons />
时,VScode 不会将我重定向到 menuButtons 组件。
Files Structure:文件结构:
│
└───src
│ App.css
│ App.js
│ App.test.js
│ index.css
│ index.js
│ menuButtons.js
│ registerServiceWorker.js
│
└───components
menuButtons.js
My App Component:我的应用程序组件:
import React, { Component } from 'react';
import './App.css';
import menuButtons from './components/menuButtons.js';
class App extends Component {
render() {
return (
<div className="App">
<footer className="App-header">
<h1 className="App-title">SPEECH RECOGNITION SYSTEM</h1>
</footer>
<menuButtons />
</div>
);
}
}
export default App;
menuButton Component:菜单按钮组件:
import React, { Component } from 'react';
export default class menuButtons extends Component {
render() {
return (
<div>
<p>Press the icon to start recording</p>
</div>
);
}
}
The directory structure does not seem right. 目录结构似乎不正确。 I recommend moving the
components
directory to src
. 我建议将
components
目录移到src
。 Then refer the import menuButtons from './components/menuButtons.js';
然后
import menuButtons from './components/menuButtons.js';
引用import menuButtons from './components/menuButtons.js';
menuButtons's directory does not seem right. menuButtons的目录似乎不正确。 its must be below example.
它必须在下面的示例中。
import menuButtons from '../components/menuButtons.js';
or 要么
you can moving the component folder to src folder then you can use 您可以将组件文件夹移动到src文件夹,然后可以使用
import menuButtons from './components/menuButtons.js';
你必须你的c omponentname更改为C omponentname(如果它不到风度工作尝试在你的组件的文件名相同的问题)
如果您在src
目录中,请尝试不使用.js
import menuButtons from './components/menuButtons';
Changed the component named from camelCase to PascalCase and it worked. 将名称为camelCase的组件更改为PascalCase,它可以正常工作。 But I am still confused because the naming convention of components in React-Native is upto user preference.
但是我仍然很困惑,因为React-Native中组件的命名约定取决于用户的偏好。
You have to rewrite the name of your component that is not rendering, instead of menuButtons change it to MenuButtons.您必须重写未呈现的组件的名称,而不是将 menuButtons 更改为 MenuButtons。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.