Basically:
I place the child component inside the parent's html.
The child component has a property
title
inside thestatic get properties()
object.In the parent component, i assign the child component's
title
property to a private variable that is not in thestatic get properties()
of the parent component.Later, in a
setTimeout
inside the parent component, i change the value of the private variable.The child component doesn't re-render.
//inside parent component
render(){
return html`
<child-component title="${this._privateVariable}"></child-component>
`
}
constructor(){
super();
this._privateVariable = 'lore ipsum'
setTimeout(()=>{
this._privateVariable = '123455667'
}, 10000)
}
Now, i know that if i put the _privateVariable
in the static get properties()
of the parent component, the child re-renders, but that's because the whole parent is re-rendering.
Once attached to the DOM, the child component is watching his title property, so it should realize that the value assigned to it changed and re-render.
I don't understand why i have to re-render the whole parent to make the child re-render.
Using the developer console and accessing the component in the DOM:
If i change the child component's property with javascript, the child re-renders perfectly fine, without me having to re-render the whole parent element.
If i edit the child component's html and manually change the attribute, the child re-renders perfectly fine, without me having to re-render the whole parent element.
What am I missing here?