这是一个 React 应用示例,展示了如何使用 useEffect 钩子在组件加载时设置页面标题。代码包含全局样式导入,并通过 MyApp 组件包装应用程序,实现了页面标题的动态设置功能。
import { useEffect } from 'react';
import '@/styles/global.css';
const MyApp = ({ pageProps }) => {
useEffect(() => {
document.title = 'hello world';
}, []);
return <Component {...pageProps} />;
};
export default MyApp;
import { useEffect } from 'react';
import '@/styles/global.css';
const MyApp = ({ pageProps }) => {
useEffect(() => {
document.title = 'hello world';
}, []);
return <Component {...pageProps} />;
};
export default MyApp;
import { useEffect } from 'react';
import '@/styles/global.css';
const MyApp = ({ pageProps }) => {
useEffect(() => {
document.title = 'hello world';
}, []);
return <Component {...pageProps} />;
};
export default MyApp;