Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

get-unhandled-props

v0.86.0arrow_drop_down
v0.86.0
v0.85.0
v0.84.0
STATUS
Passing
DOWNLOADS
10,908
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
9 months ago
SIZE
554 B
Returns an object consisting of props beyond the scope of the Component. Useful for getting and spreading unknown props from the user.
1 contributor
Use get-unhandled-props in your project ?
Copied
npm i @bit/semantic-org.semantic-ui-react.utils.get-unhandled-props
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
getUnhandledProps.js
19 Lines(9 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Returns an object consisting of props beyond the scope of the Component.
 * Useful for getting and spreading unknown props from the user.
 * @param {function} Component A function or ReactClass.
 * @param {object} props A ReactElement props object
 * @returns {{}} A shallow copy of the prop object
 */
const getUnhandledProps = (Component, props) => {
  // Note that `handledProps` are generated automatically during build with `babel-plugin-transform-react-handled-props`
  const { handledProps = [] } = Component

  return Object.keys(props).reduce((acc, prop) => {
    if (prop === 'childKey') return acc
    if (handledProps.indexOf(prop) === -1) acc[prop] = props[prop]
    return acc
  }, {})
}

export default getUnhandledProps