I've designed a quick mockup of an image uploader for an app I'm working on, and I'm now using react-cropper
as a way to crop the images to adhere to a 1:1 ratio.
TL;DR
I have a method on my Class
called cropImage
, taken from one of the examples and modified for my needs. Here's what that looks like:
cropImage() {
const { images, cropResult } = this.state;
if (typeof this.cropper.getCroppedCanvas() === "undefined") {
return;
}
this.setState({
cropResult: this.cropper.getCroppedCanvas().toDataURL(),
images: [...images, cropResult]
}, () => {
console.log(images)
})
}
What happens when this method gets called is that the array is updated and printed to the console, but not immediately. What am I missing here? I've tried to use a callback function to update the state immediately but that doesn't seem to work.
Any ideas?
More information
I'm basically trying to push the cropped images to an array, which I will later render to another component (see the flow below to see what I mean).
I assume this is the right way to go about something like this?
Flow
Not sure if this is relevant, but here's the flow just incase: