Skip to content

Instantly share code, notes, and snippets.

@SebinLee
Created May 28, 2020 07:59
Show Gist options
  • Save SebinLee/797a1df50615c6cc050872b833d59adb to your computer and use it in GitHub Desktop.
Save SebinLee/797a1df50615c6cc050872b833d59adb to your computer and use it in GitHub Desktop.
React Testing Recipe 번역 - Timer
import React, { useEffect } from "react";
export default function Card(props) {
useEffect(() => {
const timeoutID = setTimeout(() => {
props.onSelect(null);
}, 5000);
return () => {
clearTimeout(timeoutID);
};
}, [props.onSelect]);
return [1, 2, 3, 4].map(choice => (
<button
key={choice}
data-testid={choice}
onClick={() => props.onSelect(choice)}
>
{choice}
</button>
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment