Open tangway opened 6 months ago
realized through setting up tests for RTL #4 that i have not made the app show a visual change when user makes a selection so i implemented getStatus
function which will display whether the answer is correct or wrong. it runs whenever the component gets re-rendered.
so the current flow is: user makes their selection -> checkAnswer(c)
-> setCorrect
runs -> state change automatically triggers re-render of react component -> triggers getStatus()
which is inside the return of the component -> changes the STATUS msg
const getStatus = () => {
if (correct === true) return 'CORRECT';
if (correct === null) return 'MAKE SELECTION';
if (correct === false) return 'WRONG';
return 'MAKE SELECTION';
};
return (
<>
...
STATUS:
{getStatus()}
<div className="choices">
...
</>