Miss any of our Open RFC calls?Watch the recordings here! »

@simonrelet/react-utils

0.1.0 • Public • Published

@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.

getOtherProps(component, props)Object

Extract the props that are not defined in the propTypes of a component.

renderMethod(methods, props)React.Element

Render a component using of the defined methods.

setRef(ref, handler)

Provide the reference to the handler depending on the handler's type.

toInnerRef(Component)React.Component

Higher order component renaming the prop ref to innerRef.

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.

Keywords

none

Install

npm i @simonrelet/react-utils

DownloadsWeekly Downloads

3

Version

0.1.0

License

MIT

Unpacked Size

13.6 kB

Total Files

14

Last publish

Collaborators

  • avatar