You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the issues of this repository and believe that this is not a duplicate.
Reproduction link
Steps to reproduce
Open the codesandbox link , and then check the console output
What is expected?
Can successfully get the ref.current of Modal's children
What is actually happening?
It's null, so have to use a setTimeout
Environment
Info
antd
4.6.2
React
16.12.0
System
Windows 10
Browser
Google Chrome 84.0.4147.135
This bug is because when the getContainer prop to Modal is not false, the Modal component will call createContainer in the cDM which will call getContainer to create a new DOM element and append it to the document.body. But, it will not render the children at that time, on the contrary, it will trigger the forceUpdate after that, and so, the useEffect in our component will be triggered before the children be mounted to the DOM because forceUpdate is not a "sync" operation(same as setState). So, when the useEffect fired, we cant get the children DOM instance
The text was updated successfully, but these errors were encountered:
NE-SmallTown
changed the title
Modal render children it not sync which break getting ref in useEffect
Modal render children is not sync which break getting ref in useEffectSep 3, 2020
Reproduction link
Steps to reproduce
Open the codesandbox link , and then check the console output
What is expected?
Can successfully get the
ref.current
of Modal's childrenWhat is actually happening?
It's
null
, so have to use asetTimeout
This bug is because when the
getContainer
prop toModal
is notfalse
, theModal
component will callcreateContainer
in the cDM which will callgetContainer
to create a new DOM element and append it to thedocument.body
. But, it will not render the children at that time, on the contrary, it will trigger theforceUpdate
after that, and so, theuseEffect
in our component will be triggered before the children be mounted to the DOM becauseforceUpdate
is not a "sync" operation(same assetState
). So, when theuseEffect
fired, we cant get the children DOM instanceThe text was updated successfully, but these errors were encountered: