componentWillUpdate > nextProps.children is always null? #3602
-
I'm trying to It's very possible I'm going about this all wrong, but the idea is to compare the elements in componentWillUpdate(nextProps, nextState) {
const childElements = toChildArray(this.props.children).map( c => c.__e );
const nextChildElements = toChildArray(nextProps.children).map( c => c.__e );
// Unobserve children that (will) no longer exist
childElements.forEach( elem => {
if (!nextChildElements.includes(elem))
this._unobserve( elem );
});
} But from what I can see, It feels like a bug but maybe this is working as intended? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, after more debugging and looking at the data When So you can't use Makes sense, I guess :) |
Beta Was this translation helpful? Give feedback.
Ok, after more debugging and looking at the data
nextProps.children
contains duringcomponentWillUpdate()
, I think I can answer my own question.When
componentWillUpdate()
is called, Preact doesn't (yet) know / isn't concerned if the element will change, so it'snull
. I assume it's set somewhere duringrender()
.So you can't use
componentWillUpdate()
to compare current child elements vs next child elements.Makes sense, I guess :)