海口网站制作企业,响应式网站建设看什么书,公司做网站的优点,古交网站建设推广React 组件是一个 js 函数#xff0c;函数可以添加 jsx 标记
当前页使用组件#xff0c;基本使用
注意#xff1a;组件的名称#xff0c;第一个字母一定要大写#xff0c;否则会报错
import { createRoot } from react-dom/client;
import ./index.c…React 组件是一个 js 函数函数可以添加 jsx 标记
当前页使用组件基本使用
注意组件的名称第一个字母一定要大写否则会报错
import { createRoot } from react-dom/client;
import ./index.css;const root createRoot(document.querySelector(#root));// 组件的使用
const App () {const handleIncident () {console.log(组件的使用);};return (divdiv classNamebox onClick{handleIncident}inde.js 内容/div/div);
};// 使用
root.render(App /);
拆分组件使用
目录结构 index.js
import { createRoot } from react-dom/client;// 引入组件
import App from ./App;const root createRoot(document.querySelector(#root));// 使用
root.render(App /);
App.js 现在为出口文件
// 组件的使用
// 引入样式
import ./App.css;
// 引入组件
import Title from ./components/TitleData/index;// 注意组件的名称第一个字母一定要大写否则会报错
const App () {const handleIncident () {console.log(组件的使用);};return (divdiv classNamebox onClick{handleIncident}Title/Titleinde.js 内容/div/div);
};// 导出
export default App; 组件
components\TitleData\index.js
const Title () {return h1TitleData 标题/h1;
};export default Title;