Upgraded to React Native 0.62.0 Getting Warning Sign - "Calling `getNode()` on the ref of Animated component is no longer necessary

你。 提交于 2020-05-14 16:09:11

问题


I just upgrade my react native app to 0.62.0, and now my app keeps getting this warning sign

ReactNativeFiberHostComponent: Calling `getNode()` on the ref of an Animated component 
is no longer necessary. You can now directly use the ref instead. 
This method will be removed in a future release.

I'm not sure why this issue is showing up? Can someone please explain?

I also see Stack

ref.getNode |
createAnimatedComponent.js:129:20

SafeView#_updateMeasurements | index.js:192:14

SafeView#componentDidUpdate | index.js:154:9

Update

I believe this might be coming from SafeAreaView from react-navigation


回答1:


I also came to this warning after upgraded ro RN 0.62.1, and I didn't use getNode() at all, turns out it came from a depedencies that I use, called react-native-snap-carousel because they build it with FlatList and possibly using the getNode() as well.

And now there's an open issue about this in their GitHub repo that we can follow, here's the link to the issue

Update

this also came from package react-native-safe-area-view, possibly your app is using this package and now they have released new version to fix getNode() deprecation, see this PR

so instead of fixing the file directly yourself, you just need to update the package, simply run: npm i react-native-safe-area-view

Hope that's help :)




回答2:


To quick fix this go to node_modules/react-native-safe-area-view => index.js

at line 192 change

this.view.getNode().measureInWindow((winX, winY, winWidth, winHeight)

to

this.view.measureInWindow((winX, winY, winWidth, winHeight)




回答3:


As seen in the blog post announcing the release of RN62, getNode() is now deprecated. You can just use ref without calling getNode(). See this commit.




回答4:


getNode() is now deprecated on release of RN62, you can just downgrade RN to 0.61.5 and you won't get those warnings anymore.




回答5:


the issue will happen when you use createAnimatedComponent for components while its already exist in animated library for example if we use it to FlatList this warning will be showing for fix it just call componenty directly

for more detail enter link description here




回答6:


change

return this._carouselRef && this._carouselRef.getNode && this._carouselRef.getNode();

to

return this._carouselRef;

*Removing getNode() will fix it.



来源:https://stackoverflow.com/questions/60910385/upgraded-to-react-native-0-62-0-getting-warning-sign-calling-getnode-on-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!