You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React应用刷新后页面无内容显示,请求技术排查帮助

问题排查与修复

1. Greet组件缺少return语句

在Greet.js的箭头函数组件中,未返回JSX内容,导致组件渲染为空。箭头函数返回多行JSX时,需添加return或用圆括号包裹内容:

修复后的Greet.js:

import React from 'react';

const Greet = () => {
    return (
        <div>
             <h1> Hello this is mj</h1>
        </div>
    );
};

export default Greet;

也可简化为省略return的写法:

import React from 'react';

const Greet = () => (
    <div>
         <h1> Hello this is mj</h1>
    </div>
);

export default Greet;

2. React组件命名不符合规范

React要求自定义组件名必须以大写字母开头,你的meet组件为小写,会被识别为普通HTML标签而非自定义组件,无法正常渲染。需修改两处:

修复meet.js:

import React , { Component } from 'react';

class Meet extends Component {
    render() {
        return <h1> writing react </h1>
    }
};

export default Meet;

修复App.js:

import './App.css';
import Greet from './components/Greet';
import Meet from './components/Meet';


function App() {
  return (
    <div >
      <Greet />
      <Meet />
    </div>
  );
}

export default App;

完成以上修改后,重启开发服务器并刷新页面,内容即可正常显示。

内容的提问来源于stack exchange,提问作者M J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 21:54:36