prop-types-hook
v2.0.0
Published
Validate React hook props using prop-types. Dev-only — zero overhead in production.
Maintainers
Readme
prop-types-hook
Validate the props of React hooks using prop-types. Validation runs only in development — zero overhead in production.
Install
yarn add prop-types prop-types-hookUsage
Pass the hook and its prop types to withPropTypes. Defaults live in the function signature.
import React from 'react'
import PropTypes from 'prop-types'
import { withPropTypes } from 'prop-types-hook'
const useMyHook = withPropTypes(
({ oneProp = { a: 1 }, twoProp = { b: 2 } } = {}) => {
return React.useMemo(() => ({ ...oneProp, ...twoProp }), [oneProp, twoProp])
},
{
oneProp: PropTypes.object,
twoProp: PropTypes.object,
}
)Migrating from v1
withPropsValidation was renamed to withPropTypes in v2. Update your import:
-import { withPropsValidation } from 'prop-types-hook'
+import { withPropTypes } from 'prop-types-hook'The second argument for prop types is now the preferred way to pass them, instead of attaching .propTypes to the hook function. The old .propTypes property approach still works as a fallback.
