Last active
June 5, 2022 10:06
-
-
Save oney/d3a660882fa588656337492368141caf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function App({ movie }) { | |
const [uppercase, setUppercase] = useState(false); | |
const format = useCallback((str) => { | |
return uppercase ? str.toUpperCase() : str; | |
}, [uppercase]); | |
useSyncTitle(format, movie); | |
useShowRating(format, movie); | |
return ( | |
<div> | |
<Movie format={format} movie={movie} /> | |
<Click format={format} /> | |
</div> | |
); | |
} | |
function useSyncTitle(format, movie) { | |
useEffect(() => { | |
document.title = format(movie.name); | |
}, [format, movie]); | |
} | |
function useShowRating(format, movie) { | |
useEffect(() => { | |
(async () => { | |
const rating = await fetchRating(movie.id); | |
showToast(format(`This movie's rating is ${rating}`)); | |
})(); | |
}, [movie]); | |
} | |
function Movie({ format, movie }) { | |
return <h1>{format(movie.name)}</h1>; | |
} | |
function Like({ format }) { | |
return <button onClick={() => alert(format("Liked this movie"))}>Like</button>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment