Created
May 28, 2020 07:59
-
-
Save SebinLee/797a1df50615c6cc050872b833d59adb to your computer and use it in GitHub Desktop.
React Testing Recipe 번역 - Timer
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
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