1.0.2 • Published 7 years ago
@vcnkit/util v1.0.2
VCNKit/Util
@vcnkit/util
is a collection of common utility functions useful for dealing with incoming props
Installation
NPM
$ npm install --save @vcnkit/util
Yarn
$ yarn add @vcnkit/util
Usage
noop
Simple void function to use as a default prop when a function is expected.
import { noop } from '@vcnkit/util';
SomeComponent.defaultProps = {
onChange: noop,
};
omit
Omits the specified props from the given props
import { omit } from '@vcnkit/util';
const SomeComponent = (props) => (
<div { ...omit(props, [ 'someProp', 'anotherProp']) }>
'someProp' and 'anotherProp' have been omitted.
</div>
);
extract
Extracts the specified props from the given props
import { extract } from '@vcnkit/util';
const SomeComponent = (props) => (
<div { ...extract(props, [ 'role', 'id' ]) }>
'role' and 'id' will have been attached to this div.
</div>
);
extractHtmlProps
Extracts valid HTML props from the given props
import { extractHtmlProps } from '@vcnkit/util';
const SomeComponent = (props) => (
<div { ...extractHtmlProps(props) }>
Will only attach valid HTML props
</div>
);