Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

godaddy/react-component-validator

Repository files navigation

React Component validator

⚠️ DEPRECATED: This package is no longer maintained and has been deprecated. Please use an alternative solution or contact the maintainers for more information.****

Validate the instances of components that get passed as properties.

Install

npm install --save react-component-validator

Usage

Use the react-component-validator to ensure that all components in children are of type AllowedChild1 or AllowedChild2. The function should be added to propTypes.children to validate the type of children.

import validateComponents from 'react-component-validator';
import React, { Component } from 'react';

class AllowedChild1 extends Component {}
class AllowedChild2 extends Component {}

class MyComponent extends Component {
  render() {
    return <div>{this.props.children}</div>;
  }
}

MyComponent.propTypes = {
  selected: React.PropTypes.number,
  change: React.PropTypes.func,
  children: validateComponents([AllowedChild1, AllowedChild2])
};

Note: Allowed children can also be passed as a string which matches the class name. For example, validateComponents(['AllowedChild1', 'AllowedChild2'])

Whenever the Component receives children of a different type an Error will be returned, which React shows as warning.

License

See LICENSE.md

About

Validate Components through propTypes

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 6