当我使用本机0.34时,我可以执行以下操作: const ReactNativeComponentTree = require('react/lib/ReactNativeComponentTree'); let targetComponent = ReactNativeComponentTree.getInstanceFromNode(component); let inputRef = targetComponent._currentElement.props.fieldRef;,但由于更新为0.41,因此不再起作用.我收到以下错误:Unable to resolve module react/lib/ReactNativeComponentTree任何人都知道如何通过本机0.41通过其id查找元素吗?感谢您的时间!解决方案反应0.41 +:import ReactNativeComponentTree from 'react-native/Libraries/Renderer/src/renderers/native/ReactNativeComponentTree';反应0.51 +:import ReactNativeComponentTree from 'react-native/Libraries/Renderer/shims/ReactNativeComponentTree';I'm in the middle of building a react-native app and running into problems trying to find an element by it's Node ID.Some context:I'm using a Form library for my register form that has a handleFormFocus function. This gets triggered anytime any one of the inputs are focused. The parameters provided to that function are the event and the component ID (integer number), neither of which give me any useful information about which input was actually focused (i.e. "email"), but instead leave me with only an ID.When I was using react-native 0.34 I was able to do the following: const ReactNativeComponentTree = require('react/lib/ReactNativeComponentTree'); let targetComponent = ReactNativeComponentTree.getInstanceFromNode(component); let inputRef = targetComponent._currentElement.props.fieldRef;but since updating to 0.41 this no longer works. I get the following error:Unable to resolve module react/lib/ReactNativeComponentTreeAnyone know how to accomplish finding an element by its id with react native 0.41?Thanks for your time! 解决方案 React 0.41+:import ReactNativeComponentTree from 'react-native/Libraries/Renderer/src/renderers/native/ReactNativeComponentTree';React 0.51+:import ReactNativeComponentTree from 'react-native/Libraries/Renderer/shims/ReactNativeComponentTree'; 这篇关于通过节点ID查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-24 12:20