I'm updating the state of an object, say like obj = { a:1, b: ['hello','bye'] }
to setObj({ a:1, b:['hi','good'] })
. The react re-renders this ParentComponent.
//ParentComponent
return (
<>
{
obj.b.map((data,i)=>{
<ChildComponent greetings={data}/>
})
}
</>
)
But it doesn't re-render the ChildComponent, I'm new to react and still exploring new things. Please help me out with this one.
If you write like this, the ChildComponent
won't be render. Instead, you should add a return
{
obj.b.map((data,i)=>{
return <ChildComponent greetings={data}/>
})
}
or
{
obj.b.map((data,i)=>(<ChildComponent greetings={data}/>))
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.