title: Preview of uploaded image in React js using React hooks
body: <p>Using <code>React hooks</code> how can I preview the image under <code>previewProfilePic &gt; img</code> area after uploading the image via choose file input.</p>
  
  <pre><code>import React, { useState } from "react";
  
    const Register = () =&gt; {
    const [picture, setPicture] = useState(null);
  
    const onChangePicture = e =&gt; {
      console.log('picture: ', picture);
      setPicture(e.target.files[0]);
  };
    return (
      &lt;div className="register_wrapper"&gt;
        &lt;div className="register_player_column_layout_one"&gt;
          &lt;div className="register_player_Twocolumn_layout_two"&gt;
            &lt;form className="myForm"&gt;
              &lt;div className="formInstructionsDiv formElement"&gt;
                &lt;h2 className="formTitle" &gt;Sign Up&lt;/h2&gt;
                &lt;p className="instructionsText"&gt;&lt;/p&gt;
                &lt;div className="register_profile_image"&gt;
                   &lt;input id="profilePic" type="file" onChange={onChangePicture}/&gt;
                &lt;/div&gt;
                &lt;div className="previewProfilePic" &gt;
                  &lt;img className="playerProfilePic_home_tile"  src=""&gt;&lt;/img&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div className="fillContentDiv formElement"&gt;
                &lt;div className="names formContentElement"&gt;
                  &lt;input className="inputRequest " type="text" placeholder="First Name" /&gt;
                  &lt;input className="inputRequest " type="text" placeholder="Last Name" /&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div className="submitButtonDiv formElement"&gt;
                &lt;button className="submitButton"&gt;Register&lt;/button&gt;
              &lt;/div&gt;
            &lt;/form&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    );
  }
  
  export default Register;
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div className="register_profile_image"&gt;
    &lt;input id="profilePic" type="file" onChange={onChangePicture}/&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/mCJqO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mCJqO.png" alt="enter image description here"></a></p>