Skip to content

Instantly share code, notes, and snippets.

@EthanBonsignori
Last active March 19, 2021 21:26
Show Gist options
  • Save EthanBonsignori/2fba667a29545b612bcd6c989cb9ee87 to your computer and use it in GitHub Desktop.
Save EthanBonsignori/2fba667a29545b612bcd6c989cb9ee87 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
import CropModal from './CropModal';
function App() {
const [isOpen, setIsOpen] = useState(false);
const [imageBase64, setImageBase64] = useState(null);
// Placeholder, will fetch url from Database when setup
const profilePictureUrl = "https://placehold.it/200x200"
const toggleModal = () => {
setIsOpen(!isOpen)
};
const handleChange = (evt) => {
const file = evt.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
setImageBase64(reader.result)
toggleModal();
}
reader.onerror = (err) => {
console.error(err)
}
};
return (
<div className="App">
<CropModal
isOpen={isOpen}
onClose={toggleModal}
imageString={imageBase64}
/>
// other jsx here
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment