Tanpa contoh kait khusus di React
const LayoutComponent = () => {
const [onSmallScreen, setOnSmallScreen] = useState(false)
useEffect(() => {
checkScreenSize();
window.addEventListener("resize", checkScreenSize);
}, []);
let checkScreenSize = () => {
setOnSmallScreen(window.innerWidth < 700);
};
return (
<div className={`${onSmallScreen ? "small" : "large"}`}>
<h1>Hello from Default Hooks</h1>
</div>
);
};
Outrageous Ostrich