Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
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 answers
Answer question

0

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!