Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
Why changes in Checkbox's value are not displayed?

I'm using react and material ui. I need to get all checkboxes in a list checked by checking one checkbox in a parent component (i.e. I need to select all). I pass down the correct value of the parent checkbox via props, but that doesn't trigger visual changes in its children, even though their values do change to 'true'. I'm sure that the values are correct, because I tried logging them to the console.

Here's the parent:

const [checkboxValue, setCheckboxValue] = useState(false)

<Checkbox value={checkboxValue} onChange={e => setCheckboxValue(e.target.checked)}/>
{elements.map(element => (<Element selectAll={checkboxValue}/>))}

And here's the child:

function Element(props) {
    const [checkboxValue, setCheckboxValue] = useState(false)
    useEffect(() => {
        setCheckboxValue(props.selectAll)
    }, [props.selectAll])

return (
<Checkbox value={checkboxValue} onChange={e => setCheckboxValue(e.target.checked)}/>)
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you are using value instead of checked

function SingleCheckBox({ selectAll }) {
  const [checkboxValue, setCheckboxValue] = useState(selectAll);

  useEffect(() => {
    setCheckboxValue(selectAll);
  }, [selectAll]);

  return (
    <Checkbox
      checked={checkboxValue}
      onChange={(e) => setCheckboxValue(e.target.checked)}
    />
  );
}

export default function App() {
  const [checkboxValue, setCheckboxValue] = useState(false);

  return (
    <div className="App">
      <Checkbox
        checked={checkboxValue}
        onChange={(e) => {
          setCheckboxValue(e.target.checked);
        }}
      />
      <div>
        <h2>Other checkboxes</h2>
        <SingleCheckBox selectAll={checkboxValue} />
      </div>
    </div>
  );
}

https://codesandbox.io/s/angry-buck-yp7f3z?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda