React/Material-UIでheaderを実装③
19318 ワード
./components/ui/Header.js
import { AppBar, Toolbar } from "@material-ui/core";
import React from "react";
import useScrollTrigger from "@material-ui/core/useScrollTrigger";
function ElevationScroll(props) {
const { children, window } = props;
const trigger = useScrollTrigger({
disableHysteresis: true,
threshold: 0,
target: window ? window() : undefined,
});
return React.cloneElement(children, {
elevation: trigger ? 4 : 0,
});
}
const Header = () => {
return (
<ElevationScroll>
<AppBar position="fixed">
<Toolbar>Header</Toolbar>
</AppBar>
</ElevationScroll>
);
};
export default Header;
App.js
import logo from "./logo.svg";
import "./App.css";
import Header from "./components/ui/Header";
function App() {
return (
<div className="App">
<Header />
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
<p>Hello Material-UI!</p>
</div>
);
}
export default App;
Author And Source
この問題について(React/Material-UIでheaderを実装③), 我々は、より多くの情報をここで見つけました https://qiita.com/yono2844/items/c1f067e465dbdd02f690著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .