JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19
  • Score
    100M100P100Q47012F
  • License MIT

Package Exports

  • react-props-monitor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-props-monitor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-props-monitor

In-depth checking props in runtime for any React app.

npm

Install

yarn add -D react-props-monitor

or

npm install --save-dev react-props-monitor

Usage

import React from 'react';
import initPropsMonitor, { PropsMonitor } from 'react-props-monitor';

initPropsMonitor(React);

/../

render() {
  return (
    <div>
      <Root />
      <PropsMonitor />
    </div>
  );
}

ctrl+i to open a monitor.

react-props-monitor

Catch error of validation

PropTypes

PropsMonitor displays exactly which props caused the error based on PropTypes of component.

Custom validation function

You can define any validation function for props, based on prevProps, nextProps and name of component.

const costIsVerySmallNumber = ({ nextProps }) => {
  if (nextProps.value < 2000000)
    return 'Caution your cost prop is small a number.';

  return false;
};

const costShouldIncrease = ({ prevProps, nextProps, name }) => {
  if (
    name === 'TextBox' &&
    prevProps &&
    prevProps.cost > nextProps.cost
  ) {
    return 'Hey dude, I think you must to increase your cost.';
  }

  return false;
};

const validationFns = [
  costIsVerySmallNumber,
  costShouldIncrease,
];

/../

render() {
  return (
    <div>
      <Root />
      <PropsMonitor validation={validationFns} />
    </div>
  );
}

Grouping components

For a list of components you can add grouping

react-props-monitor

const groupExtraComponents = ({ name }) =>
  /^Extra/.test(name)
    ? `Extra`
    : null;

const groupsFns = [
  groupExtraComponents,
];

/../

render() {
  return (
    <div>
      <Root />
      <PropsMonitor groups={groupsFns} />
    </div>
  );
}

Coming soon

  • define and lock props
  • forecast for types based on real props in runtime