Skip to content

Instantly share code, notes, and snippets.

@EthanBonsignori
Last active March 25, 2021 17:08
Show Gist options
  • Select an option

  • Save EthanBonsignori/570297cf73eac1a24e2245da30e4c608 to your computer and use it in GitHub Desktop.

Select an option

Save EthanBonsignori/570297cf73eac1a24e2245da30e4c608 to your computer and use it in GitHub Desktop.
Second revision of App.js - adding handleChange function
import React from 'react';
function App() {
// Placeholder, will fetch url from Database when setup
const profilePictureUrl = "https://placehold.it/200x200";
const handleChange = (evt) => {
const file = evt.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
console.log(reader.result) // log Base64 for now
}
reader.onerror = (err) => {
console.error(err)
}
};
return (
<div className="App">
<h3>Profile Picture Upload</h3>
<img className="profile-picture" alt="profile" src={profilePictureUrl} />
<label className="upload-label" htmlFor="upload">Change Profile Picture</label>
<input
id="upload"
type="file"
accept="image/*" // Only accept image files (.jpg, .png, .gif, etc)
style={{ display: "none" }}
onChange={handleChange}
/>
</div>
);
};
export default App;
@EthanBonsignori
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment