0.1.0 • Published 5 years ago

@renatorodrigues/proptypes-from-json v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

React PropTypes from JSON

Auto generate React PropTypes from a JS Object

Instalation

npm install @renatorodrigues/proptypes-from-json

Reference

propTypesFromJson(json = {} \<Object>)

Returns: propTypes \<Object>

Usage

import propTypesFromJson from '@renatorodrigues/proptypes-from-json';

import MyComponent from './my-component';

const myProps = {
  "name": "The Rodrigues Family",
  "parents": [
    {
      "name": "Sergio",
      "age": 61
    },
    {
      "name": "Gislaine",
      "age": 59
    }
  ],
  "children": [
    {
      "name": "Renato",
      "age": 37
    },
    {
      "name": "Erika",
      "age": 34
    }
  ]
};

<MyComponent {...myProps} />

MyComponent.PropTypes = propTypesFromJson(myProps);

The props will be converted to:

{
  name: PropTypes.string,
  parents: PropTypes.arrayOf(
    PropTypes.shape({
      name: PropTypes.string, age: PropTypes.number
    })
  ),
  children: PropTypes.arrayOf(
    PropTypes.shape({
      name: PropTypes.string, age: PropTypes.number
    })
  )
}

2019 - Renato Rodrigues

0.1.0

5 years ago