Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Pass checkbox state to parent component so it reads it

Hey guys i'm stuck with a stupid problem where i'm having my checkbox component that sets the state of the checkbox but doesn't read it and couldn't figure out how to. I'm using the checkboxes in a modal and currently when the modal is closed, the state of the checkboxes isn't saved. So here is the component :

import { useState } from 'react';
import { handleToggle } from '../../utils';

const Checkboxes = ({ list, handleFilters }) => {
  const [checkedArray, setCheckedArray] = useState([]);

  const onChangeHandler = (checkboxId) => {
    const newState = handleToggle(checkboxId, checkedArray);
    setCheckedArray(newState);
    handleFilters(newState.map((id) => list[id].value));
  };

  return list.map((item, index) => {
    return (
      <div key={index}>
        <input
          type="checkbox"
          id={item.name}
          checked={checkedArray.indexOf(item.id) !== -1}
          onChange={() => onChangeHandler(item.id)}
        />
        <label htmlFor={item.name}>{item.label}</label>
      </div>
    );
  });
};

export default Checkboxes;

And in my app :

  const handleFilters = (checkboxState, key) => {
    const logic = 'AND';
    const newFilters = { ...selected };
    newFilters[key] = checkboxState;

Have a good monday!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda