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
}
You can use regular variable instead of state: let clickedTableRow = false