javascript - When is React.render() callback called? -
react.render(<mycomponent/>, mainnode, function() { console.log('2'); }); console.log('1');
prints
2 1
also, scrolltop() in callback not work. works if call after render() returns.
is react.render() synchronous?
is dom rendered when function returns?
when callback called? want in callback?
you can move callback logic component mounting , use componentdidmount
method first time component rendered dom, , componentdidupdate
subsequent updates/renders dom. component available in real dom via window.document
or using components getdomnode
method in both these methods.
this not quite same render callback per se. it's worth noting if you're changing state of component can pass callback function setstate
method component applied once components state has been updated (and changes rendered dom).
having looked @ react source code confirm - when rendering new root node (as per code snippet) dom process synchronous , callback (if passed) triggers after (https://github.com/facebook/react/blob/master/src/renderers/dom/client/reactmount.js lines 570-582)
Comments
Post a Comment