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

311
Visualizações
REACT-HOOKS: How do I store a modifed parameter made by the user?

I have checkboxes and I want to save in useState hooks the modified value made by the user. By default the current state is fixed and the checkbox is filled if my_value === 1, elif 0 unfilled. But if my user decides to uncheck it, how can I store this action. (if unchecked the value is 0).

Same idea with dropdown, the default value is fixed. The user can change the Taste( Good/Medium/Bad)or the Comments ((0/4....4/4)). For now I get only the current state.

export default function Display() {
    ...
    //For my checkboxes 
    const [availability, setAvailability] = useState(item.values[0].availability)
    ...
    const [trust, setTrust] = useState(item.values[0].trust)

    //For my dropdowns 
    const [taste, setTaste] = useState(item.taste)
    ...
    const [comments, setComments] = useState(rule.comments)

    function Checkbox({ value }) {
        const [checked, setChecked] = useState(value);

        return (
            <label>
                <input
                    type="checkbox"
                    checked={checked}
                    onChange={() => setChecked(checked => !checked)}
                />
                {value}
            </label>
        );
    }

    return (
        <div>
            <div>
                Availability :  <Checkbox value={!!availability} />
            </div>
            ....           
            <div > 
                Taste : <Dropdown style={styles.select} options={TASTE} defaultValue={LIKELIHOOD.find((t) => t.label === item.taste)} />
            </div>
             ...
        </div >
    );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This isn't so much a hooks problem as a "where do I store my state" problem. So far I don't see any place in your implementation to store the users choices. Either the MenuItemDisplay component needs to maintain that state, or it needs to receive it from a parent component. Either way, that state (containing user choices) will need to be passed down (along with update functions) into the checkbox component as the value of a 'checked' prop, and the update functions for that state should be passed as (and adapted to) the checkbox 'onToggle' (or similar) prop

about 4 years ago · Juan Pablo Isaza Relatório
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