My React Native component has a prop this.props.a that gets updated every 60s elsewhere in the app. Within this component, I have a <View> with an onLayout() function. This onLayout gets called every 60s when the props are updated. Is there a way to get it to be called only the first time the component is rendered, and not on subsequent re-renders?
Asked
Active
Viewed 45 times
0
gkeenley
- 4,302
- 3
- 25
- 80
-
https://stackoverflow.com/questions/12713564/function-in-javascript-that-can-be-called-only-once - looking for this? – Aseem Gautam May 04 '22 at 03:23
1 Answers
0
Yes! <View onLayout={()=> onLayout()}/> This part ()=>will prevent the onLayout function form being called on render.
Hope this helps! /W
William O'Brien
- 45
- 5