简体   繁体   English

从第三方子组件更新父状态

[英]Update parent state from third party child component

I am trying to figure out how to grab the state from a 3rd party component (which will be an array of objects) and use it to update the state in the parent component so I can access the data and do other stuff with it. 我试图弄清楚如何从第三方组件(将是对象数组)中获取状态,并使用它来更新父组件中的状态,以便我可以访问数据并对其进行其他处理。

Since the child component is third party I can not modify it and add any kind of change handler to it to pass state up. 由于子组件是第三方,因此我无法对其进行修改,也无法向其添加任何类型的更改处理程序来传递状态。

How can I achieve this? 我该如何实现?

This answer has the basic idea, although you'll want to use innerRef and React.createRef() . 尽管您将要使用innerRefReact.createRef() ,但该答案具有基本思想。 And as you mentioned, the current state can be grabbed using this.insertRefHere.current.state . 正如您提到的,可以使用this.insertRefHere.current.statethis.insertRefHere.current.state当前状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM