React Hooks 연습하기
4. useTitle
import React, { useState, useEffect } from "react";
const useTitle = (initialTitle) =>{
const [title, setTitle] = useState(initialTitle);
const updatingTitle = () => {
const htmlTitle = document.querySelector('title');
htmlTitle.innerText = title;
}
useEffect(updatingTitle, [title])
return setTitle;
}
const App1 =() => {
const titleUpdator = useTitle('loading...')
setTimeout(() => titleUpdator("✊🏽🍉🍇🍓🍋🍊🍎🍑🍑🍒🍅🥑"), 3000);
return (
<div>
<div>Hi</div>
</div>
)
}
export default App1;
4. 결과물
.gif)