0.1.0 • Published 7 years ago

@simonrelet/react-utils v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

@simonrelet/react-utils

A library of utility functions for React.

Installation

yarn add @simonrelet/react-utils
# Or
npm install --save @simonrelet/react-utils

Functions

getDisplayName(component) ⇒ string

Get the display name of a component.

Kind: global function
Returns: string - The component's name.

ParamTypeDescription
componentReact.ComponentThe 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.

ParamTypeDescription
componentReact.ComponentThe React component.
propsObjectThe props of the component.

renderMethod(methods, props) ⇒ React.Element

Render a component using of the defined methods.

Kind: global function

ParamTypeDescription
methodsObjectThe render methods.
methods.childrenReact.NodeThe children of the component. Optional.
methods.componentReact.ComponentA React component. Optional.
methods.renderfunctionA render function. Optional.
propspropsThe 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.
ParamTypeDescription
refObjectThe reference.
handlerfunction | ObjectThe handler.

toInnerRef(Component) ⇒ React.Component

Higher order component renaming the prop ref to innerRef.

Kind: global function
Returns: React.Component - The HOC

ParamTypeDescription
ComponentReact.ComponentThe React component.