在我的React Native应用程序中,我有一个包装了TextInput
的自定义组件。在使用自定义组件的代码中,我想在.focus()
上调用TextInput
。我试过像这样在自定义组件上直接调用它:
<CustomComponent
ref={ref => {
this.customComponent = ref;
}}
/>
this.customComponent.focus();
但是我不能,因为我认为自定义组件没有focus()
方法。我可以找到一种在包装的TextInput
上调用它的方法,但是我想知道是否存在一种在自定义组件上直接调用它的方法。
有人知道我该如何处理吗?
在我的React Native应用中,我有一个包装TextInput的自定义组件。在使用自定义组件的代码中,我想在TextInput上调用.focus()。我尝试直接在自定义......>
如果是类组件,则可以使用CustomComponent.prototype.yourFunction()
[youFunction
使用ref调用focus()
上的TextInput
如果CustomComponent
是您自己的组件,那么在这种情况下,您可以通过Forwarding Refs