Last active
March 19, 2021 21:26
-
-
Save EthanBonsignori/2fba667a29545b612bcd6c989cb9ee87 to your computer and use it in GitHub Desktop.
Second revision of App for tutorial: https://ethanbon.com/blog/uploading-user-cropped-profile-images-to-digital-ocean-spaces#crop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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