question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkbox when using `useTypedController` not working as expected

See original GitHub issue

Describe the bug When using useTypedController together with a @material-ui/core Checkbox component, value does not change from provided default value, and is returned as string.

Codesandbox link (Required) I’ve created a Codesandbox with two checkboxes, one with default behaviour with label “Not working” and on with my fix “Working” Codesandbox

To Reproduce

  1. Open Codesandbox link below
  2. Click “save” button. Will console log default value { notWorking: false, working: false }
  3. Check “Not working” checkbox and click “save” button. Will console log default value { notWorking: "false", working: false } (Remark string value for notWorking)
  4. Uncheck “Not working” checkbox and click “save” button. Will console log default value { notWorking: "false", working: false } (Remark string value for notWorking)

Expected behavior The value return should be of type boolean not string and change to correlate to the checkbox checked state.

Solution I’ve hijacked the onChange event handler in render props to set event.target.value to the value of checked parameter, and set property checked on Checkbox component to value. Working example can be seen in above Codesandbox link.

Desktop (please complete the following information):

  • OS: macOS 10.15.6
  • Browser Chrome
  • Version 84.0.4147.89

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebill1049commented, Aug 22, 2020

no worries @FrimJo 😃 you missed something tiny there: https://codesandbox.io/s/red-framework-oj717

1reaction
FrimJocommented, Aug 22, 2020

Thank you @bluebill1049 for clarifying ❤️

But then the docs for Strictly Typed under the Advanced section of the docs needs to be updated. There it just say to spread the props straight on to the checkbox component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does a checkbox not work as expected in Angular when I ...
I basically spent hours fixing an issue in a dynamic Angular (reactive) form that uses a checkbox. In the end, I found that...
Read more >
Checkbox inside a FormElement does not appear to work as ...
When I try to put a checkbox inside a form element the checkbox does not check and uncheck as expected. If I just...
Read more >
frontend click on a [checkbox …] field triggers validation
I checked the cf7temp.de-fra1.cloudjiffy.net site. Seemingly there is no problem with the form. The checkbox is working as expected. Thread Starter ...
Read more >
FAQs | React Hook Form - Simple React forms validation
Why is the first keystroke not working? Double check if you are using value instead of defaultValue . React Hook Form is focusing...
Read more >
Issues submitting forms with migrated Checkbox elements
Problem /Motivation This issue seems to only happen with migrated 'Checkbox' elements ('checkboxes' work great). Whenever I try to submit the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found