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 745 times
        
    0
            
            
         
    
    
        gkeenley
        
- 6,088
- 8
- 54
- 129
- 
                    https://stackoverflow.com/questions/12713564/function-in-javascript-that-can-be-called-only-once - looking for this? – A G May 04 '22 at 03:23
1 Answers
-1
            
            
        Yes! <View onLayout={()=> onLayout()}/> This part ()=>will prevent the onLayout function form being called on render.
Hope this helps! /W
 
    
    
        William O'Brien
        
- 51
- 7