From f2a56c19a78101d5418bf49e7879b4c4021a8881 Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Mon, 5 Jun 2023 17:02:44 +0800 Subject: [PATCH 1/2] Update CheckboxWithLabel.js fix input event handler function `onChange`, use the callback function to reverse the state --- examples/react-testing-library/CheckboxWithLabel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/react-testing-library/CheckboxWithLabel.js b/examples/react-testing-library/CheckboxWithLabel.js index c6355b73836f..fe5ed208fde8 100644 --- a/examples/react-testing-library/CheckboxWithLabel.js +++ b/examples/react-testing-library/CheckboxWithLabel.js @@ -6,7 +6,7 @@ export default function CheckboxWithLabel({labelOn, labelOff}) { const [isChecked, setIsChecked] = useState(false); const onChange = () => { - setIsChecked(!isChecked); + setIsChecked((draft) => !draft); }; return ( From fa3307cceb57481d49364c018423dad1a1b7219b Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Mon, 5 Jun 2023 19:44:49 +0800 Subject: [PATCH 2/2] Update CheckboxWithLabel.js fix for eslint --- examples/react-testing-library/CheckboxWithLabel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/react-testing-library/CheckboxWithLabel.js b/examples/react-testing-library/CheckboxWithLabel.js index fe5ed208fde8..861848a54c95 100644 --- a/examples/react-testing-library/CheckboxWithLabel.js +++ b/examples/react-testing-library/CheckboxWithLabel.js @@ -6,7 +6,7 @@ export default function CheckboxWithLabel({labelOn, labelOff}) { const [isChecked, setIsChecked] = useState(false); const onChange = () => { - setIsChecked((draft) => !draft); + setIsChecked(draft => !draft); }; return (