I think I misunderstood some fundamental: I want to know, how can I call a method from a child component in a parent component, especially when use it in a list?
{this.items.map((item) => {
let textRef // does not work
return (
<div key={item.id} pointerdown={() => textRef.doSomething()}>
<Child ref={textRef} />
</div>
)
})}
Refs only work with dom nodes.
Store solution with observe (for calling a method) or props with observe are an overkill for a simple method call.
I think I misunderstood some fundamental: I want to know, how can I call a method from a child component in a parent component, especially when use it in a list?
Refs only work with dom nodes.
Store solution with observe (for calling a method) or props with observe are an overkill for a simple method call.