Skip to content

Instantly share code, notes, and snippets.

@aem
Created November 26, 2019 03:43
Show Gist options
  • Save aem/93b0ef5ef763449f05d3a4bc394a1898 to your computer and use it in GitHub Desktop.
Save aem/93b0ef5ef763449f05d3a4bc394a1898 to your computer and use it in GitHub Desktop.
function usePrevious(value) {
const prevRef = useRef();
useEffect(() => {
prevRef.current = value;
}, [value]);
return prevRef.current;
}
function Player({ online, playbackStatus, reload }) {
const prevOnline = usePrevious(online);
const prevPlaybackStatus = usePrevious(playbackStatus);
useEffect(() => {
if (!prevOnline && online) {
if (prevPlaybackStatus !== ERROR && playbackStatus === ERROR) {
reload();
}
}
});
return <div className="App">👋</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment