Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 870 Bytes

README.md

File metadata and controls

43 lines (32 loc) · 870 Bytes

Proptype

The Proptype determines if the data provided is compliant with the schema in the context of a React proptype.

Proptype depends on a Validator module set to the validate key.

Setup

import create from 'single-schema/lib';
import Validator from 'single-schema/lib/flatteners/validate';
import Proptype from 'single-schema/lib/flatteners/proptype';

const flatteners = {
	validate: Validator(),
	proptype: Proptype(),
};

const { combine, array, map, and, maybe } = create(flatteners);
const string = {
	validate: value => typeof value == 'string'
	? null
	: 'Must be string',
};

const { proptype } = combineReducers({
	key: string,
});

const Component = () => <div />;
Component.propTypes = {
	test: proptype(),
};

// warns
<Component test={{key: 123}} />

// does not warn
<Component test={{key: 'hello'}} />