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

125
Views
How do i reference a button state in another component react js

Trying to get the button state from NavBar into iFramePage but it will always render as the variable as null.

// NavBar.js

class ButtonExample extends React.Component {
    state = { status: false }
    render() {
      const { status } = this.state;
      return (
        <button id="button1" value={status} onClick={() => this.setState({ status: !status })}>
          {`${status ? 'dark' : 'light'}`}
        </button>
      );
    }
  }

const NavBar = (props) => (
    <AppBar {...props} >
        <ButtonExample/>
    </AppBar>       
);
export default NavBar;
// iFramePage.js
let mode,
    element = document.getElementById("button1");
if (element != null) {
    mode = element.innerText;
}
else {
    mode = null;
}

const path = ("http://127.0.0.1/kiosk&theme=")

const iFramePage = () => (
    <div>
    <iframe src={ path + mode } /> 
);

export default iFramePage;

If i put a button function on iFramepage to console log the value from NavBar it will return the value correctly. So i would presume its down to timing of the rendering of the page?

function  GetMode () {
  let str,
    element = document.getElementById("button1");
if (element != null) {
    mode = element.innerText;
}
else {
    mode = null;
}
  console.log(mode)
}
...
<button label="GetMode" onClick={() => { GetMode();}} /> 
...
about 4 years ago · Juan Pablo Isaza
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!