0.2.12 • Published 7 years ago

react-props-monitor v0.2.12

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

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
0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.1

7 years ago