Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native get default style props?

Tags:

react-native

How can I get the default style props from inside my React Native app or with a debugging tool? I tried with React Devtools, but they only show the props that I set, not the default ones. But I am interested in the default values. How can I watch them? I do not want to depend on the documentation and want to really check it in my running app. I am using functional components.

like image 596
stefan.at.wpf Avatar asked Jun 29 '26 14:06

stefan.at.wpf


1 Answers

You can get and modify default props by importing that component. For example, I used the following code to modify FlatList behavior globally including node modules that I am using:

if (FlatList.defaultProps == null) {
  FlatList.defaultProps = {}
}
FlatList.defaultProps.initialNumToRender = 10
FlatList.defaultProps.maxToRenderPerBatch = 10
FlatList.defaultProps.scrollEventThrottle = 15
FlatList.defaultProps.bounces = false

I believe that you can use console.warn or console.log inside render method of a scene to see its content.

Inside render block place following code:

render(){
   console.warn(FlatList.defaultProps)
   return (
     <View>
     ...
     </View>
    )
}

enter image description here

like image 193
Mohammad f Avatar answered Jul 01 '26 13:07

Mohammad f



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!