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

87
Visualizações
How to reset state variable value to its initial value always when a component is rendered in React

I have a React component which is like a graph where you can click on different nodes to get additional info. I have a boolean state variable (clickedNode) in this component to determine if I need to render another component (basically tables with info) when a node is clicked. So from this graph component, I'm calling this table component and in the table component I have another state variable (clickedTableRow). Basically, I want this state variable to initialize to false always when this table component is rendered. I have some logic which sets this variable to true in table component but how can I initialize this variable to false always when table component is called from the graph component?

For reference, this is the template for my code:

  const Graph=()=>{

    //graph rendering code

    {clickedNode?(<div> <Table /> </div>):("")}

  }

  const Table = props => {

    let[clickedTableRow,setTableRowClicked]=useState(false)  // I want clickedTableRow to be initialized to false always

    //rest of the table code
  }
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use regular variable instead of state: let clickedTableRow = false

about 4 years ago · Santiago Trujillo 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