@simonrelet/react-utils
v0.1.0
Published
A library of utility functions for React.
Readme
@simonrelet/react-utils
A library of utility functions for React.
Installation
yarn add @simonrelet/react-utils
# Or
npm install --save @simonrelet/react-utilsFunctions
getDisplayName(component) ⇒ string
Get the display name of a component.
Kind: global function
Returns: string - The component's name.
| Param | Type | Description | | --------- | ---------------------------- | -------------------- | | component | React.Component | The React component. |
getOtherProps(component, props) ⇒ Object
Extract the props that are not defined in the propTypes of a component.
Kind: global function
Returns: Object - The other props.
| Param | Type | Description | | --------- | ---------------------------- | --------------------------- | | component | React.Component | The React component. | | props | Object | The props of the component. |
renderMethod(methods, props) ⇒ React.Element
Render a component using of the defined methods.
Kind: global function
| Param | Type | Description | | ----------------- | ---------------------------- | ---------------------------------------- | | methods | Object | The render methods. | | methods.children | React.Node | The children of the component. Optional. | | methods.component | React.Component | A React component. Optional. | | methods.render | function | A render function. Optional. | | props | props | The props to pass down. Optional. |
setRef(ref, handler)
Provide the reference to the handler depending on the handler's type.
Kind: global function
Throws:
- Error Will throw an error for unsupported handler types.
| Param | Type | Description | | ------- | -------------------------------------------- | -------------- | | ref | Object | The reference. | | handler | function | Object | The handler. |
toInnerRef(Component) ⇒ React.Component
Higher order component renaming the prop ref to innerRef.
Kind: global function
Returns: React.Component - The HOC
| Param | Type | Description | | --------- | ---------------------------- | -------------------- | | Component | React.Component | The React component. |
