I am trying to do display some data in the child component from Parent Component where my parent Component has an object variable that am using to display on my child component.
Here's Simple Snippet:
<template>
Display Child Component Here::
<template for:each={ceoList} for:item="item" for:index="i">
<td key={item.id}>
<c-render-changes-to-child item={item}></c-render-changes-to-child>
</td>
</template>
<lightning-button onclick={changeHandler} label="Submit"></lightning-button>
</template>
import { LightningElement, api } from 'lwc';
export default class RenderChangesFromParent extends LightningElement {
@api ceoList=[
{id:"1", Company:"Google", Name:"Sunder Pichai"},
{id:"2", Company:"Apple", Name:"Tim Cook"},
{id:"3", Company:"Facebook", Name:"Mark Zuckerberg"}
]
changeHandler(){
ceoList[2].Company = "Toyota"
ceoList[2].Name = 'Akio Toyoda'
console.log(ceoList);
}
}
and my child Component is::
<template>
Company Name is : {item.Company} <br></br>
Company Ceo is : {item.Name}<br></br>
</template>
import { LightningElement, api } from 'lwc';
export default class RenderChangesToChild extends LightningElement {
@api item;
}
Onload it works perfectly fine. However, on a click of button I want to make changes to my object variable and also want this to reflect on child. Is there a way to refresh my child component to reflect the changes?
Appreciate your help!