From 0f5e68854c376283fb39051667ae89bb5ea41bf5 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Wed, 31 May 2023 18:04:19 +0200 Subject: [PATCH] Fix IdealImage trying to load() the picked image onEnter before the image url has been set to state. Not sure why it worked before, but with React 18 this definitively fail, and it's not expected to be able to see your reads --- src/components/IdealImage/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/IdealImage/index.js b/src/components/IdealImage/index.js index ef98e9f..6578042 100644 --- a/src/components/IdealImage/index.js +++ b/src/components/IdealImage/index.js @@ -320,8 +320,9 @@ export default class IdealImage extends Component { ...this.state, // eslint-disable-line react/no-access-state-in-setstate size: pickedSrc.size, }) - this.setState({pickedSrc, shouldAutoDownload, url}) - if (shouldAutoDownload) this.load(false) + this.setState({pickedSrc, shouldAutoDownload, url},() => { + if (shouldAutoDownload) this.load(false) + }) } onLeave = () => {