Skip to content

Allow for Generation of Custom Prop TypesΒ #28

@markalfred

Description

@markalfred

Airbnb created a number of custom prop types (https://github.com/airbnb/prop-types), and we should allow for the generation of these (and any other) custom types. For instance, using their empty validator:

const customGenerators =  { empty: () => null }

generateProps.init({ generators: customGenerators })
// Note: init doesn't currently take any options

import { empty } from 'airbnb-prop-types'
Component.propTypes = { alwaysEmpty: empty.isRequired }

generateProps(Component)
// => Current: {}
// => Proposed: { alwaysEmpty: null }

A real world example that I'd like right now:

generateProps.init({ generators: { dateString: () => moment().format() } })

import { dateString } from 'lib/custom-prop-types'
Component.propTypes = { insertedAt: dateString.isRequired }

generateProps(Component)
// => Current: {}
// => Proposed: { insertedAt: '2019-06-12T17:23:27-04:00' }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions