Created
February 5, 2018 06:43
-
-
Save eddyw/bca63e43a83b34ad9e125f95c9c1567f to your computer and use it in GitHub Desktop.
Type-checking Redux State with propTypes (without React)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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