What's the time complexity for the React component lifecycle?
I was reading a post here recently that suggested where a closure was called for, it could be a good idea to use a component instead. In term of vanilla JavaScript, time complexity should be the same or similar since in the end both are functions. Space complexity may be larger for the component. But the component has to go through the React lifecycle, correct? Which I assume adds overhead.
My intuition says that the complexity is O(n)
A quick peak at the reconciliation docs seems to support my intuition.
Every operation, lifecycle or not, will at most happen just once per node in the tree, so upper limit of O(n * ops)
However in practice it is likely way less since components don't always render thanks to shouldComponentUpdate
, and other sub-tree rendering techniques.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With