New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-simple-default-props

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-simple-default-props

Simplest way to set default props for react-native components

1.0.0
latest
Source
npm
Version published
Weekly downloads
930
-13.41%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-simple-default-props

Simplest way to set default props of any react-native components even Custom Component

Motivation

react-native-global-props has not update since Oct 2018
It's useful but not work in some cases and import every single function for each component are not smart
So I used my own version

recently I thouhgt someone has same needs,
I hope react-native-simple-default-props could help you

Installation

npm i react-native-simple-default-props
or
yarn add react-native-simple-default-props

Usage

// import
import setDefaultProps from 'react-native-simple-default-props'

// use
setDefaultProps(Component, props)

Example

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 (
    <SafeAreaView {...props}>
      <Text>{text}</Text>
    </SafeAreaView>
  );
};

setDefaultProps(CustomComponent, {style: {backgroundColor: 'lightgreen'}});

const App = () => {
  return (
    <SafeAreaView style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
      <Text>TEXT</Text>
      <TextInput />
      <CustomComponent text="CustomComponent1" />
      <CustomComponent text="CustomComponent2" />
    </SafeAreaView>
  );
};

export default App;
  • Example Image

Keywords

react-native

FAQs

Package last updated on 10 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts