1.0.3 • Published 5 years ago

inferno-render-delay v1.0.3

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

Inferno Render Delay

npm version

Delay the (re)rendering of stateless components by a set amount of time.

In Javascript, sometimes we use setTimeout to make sure that the renderer gets ran before any major thread-blocking computations. This small higher-order component allows us to do this with Inferno components without adding additional state to otherwise simple components.

Installation

npm install inferno-render-delay

Documentation

function withRenderDelay(wrappedComponent, options?)
  • wrappedComponent: The stateless component to be delayed.

  • options

    • delay (number): Milliseconds to wait before (re)rendering. Defaults to 1.
    • delayFirstRender (bool): True to delay the initial render. Defaults to false.

Example

import {render} from 'inferno'
import withRenderDelay from 'inferno-render-delay'

const Message = (props) => <p>{props.text}</p>
const DelayedMessage = withRenderDelay(Message, { delay: 500, delayFirstRender: true })

render(
  <div>
    <Message text="hello" />
    <DelayedMessage text="world" />
  </div>, 
  document.getElementById('root')
)

Use Cases

Simple Delay

No DelayDelay
no-delay-computationdelay-computation

Deferring Expensive Computations

No DelayDelay
no-delay-computationdelay-computation

Waiting For User Input

No DelayDelay
no-delaywith-delay