From the React 16 docs about ReactDOM.hydrate()
,
Same as render(), but is used to hydrate a container whose HTML contents were rendered by ReactDOMServer. React will attempt to attach event listeners to the existing markup.
Will
ReactDOM.hydrate()
also trigger lifecycle methods on the client such ascomponentWillMount()
,componentDidMount()
during initial render?Will
render()
method be called on the client during hydration? I suppose not, because that's the difference betweenReactDOM.render()
andReactDOM.hydrate()
?
If render
method won't be called on the client, we wouldn't expect componentDidMount()
lifecycle method to be triggered.
If none of the lifecycle methods are called on the client, how would we know when has React finished rendering. I suppose the callback
in the following syntax:
ReactDOM.hydrate(element, container[, callback])
I want to understand if there are lifecycle methods / hooks (which give more control over the application) available when React is "attempting to attach event listeners to existing markup".
componentWillMount
is called both on the server and on the client after callinghydrate
. I'm trying to find a way to differentiate between an element being mounted and hydrated and having trouble. ideas welcome! – Coldblooded