Skip to content

Instantly share code, notes, and snippets.

@oney
Last active June 5, 2022 10:06
Show Gist options
  • Save oney/d3a660882fa588656337492368141caf to your computer and use it in GitHub Desktop.
Save oney/d3a660882fa588656337492368141caf to your computer and use it in GitHub Desktop.
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