Skip to content

Instantly share code, notes, and snippets.

@eddyw
Created February 5, 2018 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddyw/bca63e43a83b34ad9e125f95c9c1567f to your computer and use it in GitHub Desktop.
Save eddyw/bca63e43a83b34ad9e125f95c9c1567f to your computer and use it in GitHub Desktop.
Type-checking Redux State with propTypes (without React)
const withPropTypes = (name, propTypesSchema) => reducer => {
if (process.env.NODE_ENV === 'development') {
return (state, action) => {
const result = reducer(state, action)
propTypes.checkPropTypes(
{ state: propTypesSchema },
{ state: result },
'property',
name,
)
return result
}
}
return reducer
}
export default withPropTypes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment