function App = () => {
return (
<h1>Hello</h1>
);
}
export const useTitle = (initialTitle) => {
const [title, setTitle] = useState(initialTitle);
const updateTitle = () => {
const htmlTitle = document.querySelector("title");
htmlTitle.innerText = title;
};
useEffect(updateTitle, [title]);
return setTitle;
};
import useTitle from "./useTitle"
function App = () => {
const titleUpdater = useTitle("Loading...");
setTimeout(() -> titleUpdater("Hello!"), 5000);
useEffect
return (
<h1>Hello</h1>
);
}
출처:
https://ko.reactjs.org/docs/hooks-custom.html
https://www.youtube.com/watch?v=J8E9CEyBbWo&t=135s