title: Reactjs: How to Off and On Webcam in reactjs
body: <p>The Code below was use to capture Webcam photos. Source link is written below
  <a href="https://www.npmjs.com/package/react-webcam" rel="nofollow noreferrer">https://www.npmjs.com/package/react-webcam</a></p>
  
  <p>//npm install react-webcam</p>
  
  <p><strong>Here is my issue,</strong> When the Page loads, The Webcam pointer is immediately on/activated and I believe this is not proper.
   what If the 
  user does not want to capture the webcam photos immediately.</p>
  
  <p><strong>My question is:</strong> Is there anyway I can add a button to turn on or off the webcam via reactjs. To this effect, I have created this button below but cannot turn on the Camera when click</p>
  
  <pre><code> &lt;button onClick={this.setRef}&gt;Turn On/Off Camera&lt;/button&gt;
  </code></pre>
  
  <p>Here is the main code.</p>
  
  <pre><code>import React from "react";
  import ReactDOM from "react-dom";
  
  import Webcam from "react-webcam";
  class App extends React.Component {
  
  
   setRef = webcam =&gt; {
      this.webcam = webcam;
    };
  
    capture = () =&gt; {
      const imageSrc = this.webcam.getScreenshot();
  alert(imageSrc);
    };
  
  
  
    render() {
   const videoConstraints = {
        width: 1280,
        height: 720,
        facingMode: "user"
      };
  
      return (
        &lt;div&gt;
          &lt;Webcam
            audio={false}
            height={350}
            ref={this.setRef}
            screenshotFormat="image/jpeg"
            width={350}
            videoConstraints={videoConstraints}
          /&gt;&lt;br /&gt;
  
          &lt;button onClick={this.capture}&gt;Capture and Submit photo&lt;/button&gt;
        &lt;/div&gt;
      );
    }
  }
  </code></pre>