prop-types-hook

1.0.0 • Public • Published

prop-types-hook

Provide a mechanism to validate the props of React hook(s) using prop-types.

Install

yarn add prop-types prop-types-hook

Usage

import { withPropsValidation } from 'prop-types-hook'

const useMyHook = (props) => {
  const { oneProp, twoProp } = props
  
  const result = React.useMemo(() => {
    return {
      ...oneProp,
      ...twoProp,
    }
  }, [])

  return result
}

useMyHook.propTypes = {
  oneProp: PropTypes.object,
  twoProp: PropTypes.object,
}

useMyHook.defaultProps = {
  oneProp: { a: 1 },
  twoProp: { b: 2 },
}

// Resulting hook with validation
const useHook = withPropsValidation(useMyHook)

Author

Prolincur Technologies

Readme

Keywords

Package Sidebar

Install

npm i prop-types-hook

Weekly Downloads

2

Version

1.0.0

License

Apache-2.0

Unpacked Size

15.3 kB

Total Files

6

Last publish

Collaborators

  • prolincur