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.
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'}} />