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

160
Visualizações
Change button caption by condition React jsx

There is a button on the notes page with a deactivation function, there is a note object (todo) it has an is_active property with a value of False or True , this property changes when clicked please tell me how to make it so that when the button is pressed, the inscription changes along with the value: "Open" : "Closed", how and where to write the condition correctly. I found an option, but for some reason it does not work. Here is my note code:

const TodoItem = ({todo, deleteTODO}) => {
    // <div>if todo.is_active === 'True' ? button:'Open' : button:'Closed'</div>
    return (
        <tr>
            <td>{todo.id}</td>
            <td>{todo.name_project}</td>
            <td>{todo.text}</td>
            <td>{todo.date_create}</td>
            <td>{todo.date_update}</td>
            <td>{todo.creator}</td>
            {/*<td>{todo.is_active}</td>*/}
            <td>
                {todo.is_active === 'True' ?
                <button onClick={() => deleteTODO(todo.id)}  type='button'>Open </button>:
                <button onClick={() => deleteTODO(todo.id)}  type='button'>Closed </button>}
            </td>
        </tr>
    )
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm assuming that you want to change the text of button based on the boolean value of is_active then this would work.

<td>
  <button onClick={() => deleteTODO(todo.id)}>
    { todo.is_active ? "Open" : "Close" } 
  </button>
</td>
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