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.

Runtime error with Checkbox and Material-UI v4

See original GitHub issue

Just a heads-up. This may be due to changes in Material-UI v4 alpha.

The following:

<Field
  Label={{ label: 'Do you confirm?" }}
  name='confirmation'
  component={CheckboxWithLabel}
  color='primary'
/>

At runtime was causing:

Warning: Failed prop type: Invalid prop `checked` of type `string` supplied to `ForwardRef(Checkbox)`, expected `boolean`.
    in ForwardRef(Checkbox) (created by WithStyles(ForwardRef(Checkbox)))
    in WithStyles(ForwardRef(Checkbox)) (created by FormikMaterialUICheckboxWithLabel)
    in label (created by ForwardRef(FormControlLabel))
    in ForwardRef(FormControlLabel) (created by Context.Consumer)
    in WithFormControlContext(ForwardRef(FormControlLabel)) (created by WithStyles(WithFormControlContext(ForwardRef(FormControlLabel))))
    in WithStyles(WithFormControlContext(ForwardRef(FormControlLabel))) (created by FormikMaterialUICheckboxWithLabel)

Changing this:

https://github.com/stackworx/formik-material-ui/blob/8d8b6abf18e6ce9f95020eb6f9ce9f9c6b6b8e10/src/Checkbox.tsx#L26

To:

    checked: field.value

That is, leaving the boolean value alone, not converting it to string, fixed it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
cliedemancommented, May 8, 2019

I think we should only merge the PR when 4 is released as we should bump the peer dependency 4.0 >=.

In the meantime you can use this:

import {
  Checkbox as MuiCheckbox,
} from '@material-ui/core';
import {
  CheckboxProps,
  fieldToCheckbox,
} from 'formik-material-ui';


const Mui4Checkbox = (props: CheckboxProps) => {
  return (
    <MuiCheckbox {...fieldToCheckbox(props)} checked={props.field.value} />
  );
};
2reactions
johnrazcommented, May 27, 2019

I couldn’t find a PR so I went ahead an created it here: #75

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrade from v3 to v4 - Error: Cannot find module #16468
Lets have a look into /node_modules/@material-ui/core/esm/Checkbox/Checkbox.js. The import causing this error is in line 6: import SwitchBase ...
Read more >
my checkbox (material-ui) is not disabling - Stack Overflow
On the material ui docs page for checkbox components (https://material-ui.com/api/checkbox/#checkbox-api). It lists the disabled attribute ...
Read more >
How to use Material UI Checkbox - Refine Dev
This article will deeply traverse the Material UI Checkbox component, investigate its processes and highlight its syntax application.
Read more >
React Checkbox component - Material UI - MUI
Checkboxes allow the user to select one or more items from a set. Checkboxes can be used to turn an option on or...
Read more >
androidx.compose.material - Android Developers
Represents the colors used by the three different sections (checkmark, box, and border) of a Checkbox or TriStateCheckbox in different states.
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