Note: This is a short warm up question meant to help you familiarize with the coding workspace. Actual UI coding interview questions will be more complicated.
Make the text within the button display the number of times the button has been clicked.
This is a short question which only requires one state variable, which is the number of times the button has been clicked (count
).
useState
can be used to track that variable and replace the hardcoded 0 with the count
state. Then attach an onClick
handler on the <button>
element and increment the count
whenever it is clicked.
<!doctype html><html lang="en"><head><meta charset="UTF-8" /><metaname="viewport"content="width=device-width, initial-scale=1.0" /></head><body><div id="root"></div></body></html>
console.log()
statements will appear here.