I couldn't understand this issue.
please explain me about this.
I attach source code and error image.
https://github.com/elitesuper/my_issue/blob/main/CollectionUpload.tsx
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (5)
The React error message tells you exactly what the problem is. The
CollectionUpload
component state is being updated while rendering the componentUploadProgress
.So let's break down what's happening here.
Function Component Render Cycle
In a React function component the function body is basically the render method of the component. Whatever happens inside the function component body, happens during that component's render cycle.
You need to be careful with updating state from there, especially when it's the state of another component.
Cause Of The Error Message
Your
UploadProgress
component has the following lines of code that probably cause the problem:It's the
setupload(true)
call which updates the state of theCollectionUpload
component whileUploadProgress
is being rendered.Effect Hooks Solve The Problem
Effect hooks can be used for deferring the execution of code after the component was rendered, so basically after the function component was called and returned its render result. You can look at them as callback functions that are queued for execution after component rendering took place.
You could wrap that problematic if statement that calls
setupload(true)
in anotheruseEffect
to solve the problem.π Thank you very much, Your method is very useful!
π Thanks for your message!
Let me check.
kind regards!
Split the UploadProgress component into another file, then import it and use it in CollectionUpload
π Thanks for your message!!!
But This Warning still exist.
please check this.
github.com/elitesuper/my_issue