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?
Yes! <View onLayout={()=> onLayout()}/>
This part ()=>
will prevent the onLayout function form being called on render.
Hope this helps! /W