Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-require-props
Advanced tools
Readme
This simple library assists with enforcing data schemas for React.js component properties. It can theoretically be used to verify data types within any object, too.
npm install react-require-props --save
...or
yarn add react-require-props
RequireProps(componentName, props, required, other, disabled);
componentName
(string): The name of your Component. Helpful for debugging.props
(object): The props
object of your component.required
(array|object): Which properties are required? See below for examples.other
(object): Data type validations for non-required properties. See below for examples.disabled
(boolean): If true
, the validations will not run.RequireProps
in the constructor of your component:import React from 'react';
import RequireProps from 'react-require-props';
class MyComponent extends React.Component {
constructor(props) {
super(props);
RequireProps('MyComponent', props, ['image', 'text']);
}
}
<MyComponent image='./demo.jpg' text='Hello, world!' />
<MyComponent text='Hello, world!' /> {/* <-- Throws an error */}
RequiredProps also allows you to enforce specific data types for properties:
RequireProps('MyComponent', props, {
'image': Array,
'text': String
});
<MyComponent text='Hello, world!' /> {/* <-- Throws an error */}
<MyComponent image='./demo.jpg' text='Oops.' /> {/* <-- Throws an error */}
<MyComponent image={['./demo.jpg', 'Demo']} text='All good!' />
Types available are:
String
Boolean
Number
Function
Array
Object
You can also enforce the data type of parameters which aren't required. This can be achieved by passing in a fourth argument to the function:
RequireProps('MyComponent', props, {
'image': Array,
'text': String
}, {
visible: Boolean
});
<MyComponent image={['./demo.jpg', 'Demo']} text='All good!' />
<MyComponent image={['./demo.jpg', 'Demo']} text='All good!' visible={true} />
<MyComponent image={['./demo.jpg', 'Demo']} text='Oops.' visible='yes' /> {/* <-- Throws an error */}
FAQs
Define property schemas for React.js components.
The npm package react-require-props receives a total of 0 weekly downloads. As such, react-require-props popularity was classified as not popular.
We found that react-require-props demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.