I've a question about what it is the best way to pass some value from a father component to a child component and show the value, because I've tried to pass value with properties and slot and both ways work.
Properties: I've a movement list and use repeat
from lit-html (and method html
to render) in the father component in order to create n child component giving the values in them properties.
//father component
render(){
return html`
${repeat(movements, movement => movement.id, (movement, index)=> html`
<movement
.id=${movement.id} .description=${movement.description} .amount=${movement.amount} .balance=${movement.balance}>
</movement>
<hr>
`)}
`
}
//child component
render(){
return html`
<dt>${this.id}</dt>
<dl>${this.description}</dl>
<dl>${this.amount}</dl>
<dl>${this.balance}</dl>
`;
}
Slot: I've a movement list and use repeat
from lit-html (and method html
to render) in the father component in order to create n child component giving the values in slot which were declared in the child component
//child component
render(){
return html`
<dd>
<slot name="id"></slot>
<slot name="description"></slot>
<slot name="amount"></slot>
<slot name="balance"></slot>
</dd>
`;
}
//father component
render(){
return html`
${repeat(movements, movement=>movement.id, (movement, index)=>html`
<movement>
<dt slot="id"> ${movement.id} </dt>
<dl slot="description"> ${movement.description} </dl>
<dl slot="amount"> ${movement.amount} </dl>
<dl slot="balance"> ${movement.balance} </dl>
</movement>
`)}
`;
}
Which it is the best way? When do I have to use one and the other?
Here is an example to pass of
object's properties
with usingLitElement
:DEMO