Why do Material UI CheckBox appear twice on the first render?

Viewed 273

A weird thing is happening with my checkboxes and I can't figure it out. The first time the component loads, each checkbox appears twice. 2nd and subsequent loads are OK. Here is my code:-

const ModifierGroups = () => {
        return (
            modifierGroups.map(modifierGroup => (
                <div>
                    <FormControlLabel
                        className={classes.checkBoxes}
                        label={modifierGroup.Name}
                        control={
                            <MUICheckbox
                                checked={true}
                                name={modifierGroup.Name}
                                size="small" />
                        }
                />
                </div>
            ))
        )
    }

and this is what it looks like the first time it loads

CheckBoxes Shown Twice

2 Answers

One possible solution is to close the running react app and open it again. This worked for me and the problem didn't show up again.

I do not have any deep understanding of why it worked, but I believe that is because I'm using NextJs, and NextJs builds a static version of the app when starting with "yarn dev", which maybe caused a render issue with the new imported Checkbox.

I tried putting the tag around the checkbox and it worked.

Related