Simplest way to set default props for react-native components
npm install react-native-simple-default-propsbash
npm i react-native-simple-default-props
or
yarn add react-native-simple-default-props
`$3
`js
// import
import setDefaultProps from 'react-native-simple-default-props'// use
setDefaultProps(Component, props)
`$3
`js
import React from 'react';
import {Text, TextInput, SafeAreaView} from 'react-native';
import setDefaultProps from 'react-native-simple-default-props'const defaultText = {
style: [{color: 'orange'}, {fontSize: 30}],
};
// usage
setDefaultProps(Text, defaultText);
setDefaultProps(TextInput, {
underlineColorAndroid: 'transparent',
placeholder: 'this is placeholder',
style: {
fontSize: 30,
padding: 0,
},
});
// work with Custom Component also
const CustomComponent = ({text = '', ...props}) => {
return (
{text}
);
};
setDefaultProps(CustomComponent, {style: {backgroundColor: 'lightgreen'}});
const App = () => {
return (
TEXT
);
};
export default App;
``- Example Image