NodeJS ReactJS不加载[关闭]

sigwle7e  于 9个月前  发布在  Node.js
关注(0)|答案(3)|浏览(108)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
一年前关闭。
Improve this question
嗨,我是reactJS的菜鸟,所以我对它有很多了解。
我刚刚完成了项目的页眉,现在我正在处理页脚。问题是,如果我在index.js中导入页脚,当页面刷新时,它不会加载。
我的index.js看起来像这样:

import React from 'react';
import ReactDOM from 'react-dom';

//Components
import Header from './component/header/Header';
import Footer from './component/footer/Footer';

//SCSS
import './index.scss';
import './custom.scss';

const app = (

  <div>
    <Header />

    <Footer />
  </div>

);

ReactDOM.render(
  app,
  document.getElementById('root')
);

字符串
我尝试更新node和react,升级package.json中的内存量,但这些都不起作用。

ldfqzlk8

ldfqzlk81#

组件应该是一个函数,并且应该像这样大写

const App = () => (
 <div>
    <Header />
    <Footer />
  </div>
);

字符串
然后你应该像这样开始你的申请

ReactDOM.render(
  <App />,
  document.getElementById("root"),
);


关于组件的命名,请查看文档的此部分
https://reactjs.org/docs/components-and-props.html#rendering-a-component
特别是,这就是为什么为组件使用大写名称很重要(来自React文档)。

备注:始终以大写字母开头的组件名称。React将以小写字母开头的组件视为DOM标记。例如,<div />表示HTML div标记,但<Welcome />表示组件,并要求Welcome在范围内。

p4rjhz4m

p4rjhz4m2#

你的语法不正确

import React from 'react';
import ReactDOM from 'react-dom';

//Components
import Header from './component/header/Header';
import Footer from './component/footer/Footer';

//SCSS
import './index.scss';
import './custom.scss';

const App = () => {
  return(
    <div>
    <Header />
    <Footer />
    <div>
  )
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

字符串

dzjeubhm

dzjeubhm3#

好吧,我已经改变了它,但仍然不工作。当我开始与-npm开始-它显示这几秒钟

PS H:\...\hardysoft> npm start

> [email protected] start
> react-scripts --max_old_space_size=4096 start

(node:14928) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...' to show where the warning was created)
(node:14928) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.

字符串

相关问题