npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

faizrr.react-debounce-render

v4.0.1

Published

A React higher order component that will debounce the rendering of your React components

Downloads

3

Readme

react-debounce-render

react-debounce-render is a Higher Order Component that wraps your react components and debounces their rendering.

This method can be used to prevent extra renders when a react component rapidly receives new props by delaying the triggering of the render until updates become less frequent. Doing so will improve the overall rendering time of the application, thus improve the user experience. It uses lodash debounce under the hood.

Rationale:

Sometimes it's difficult, impractical or impossible to batch props updates before they're passed down to a react component, resulting in a react component being rendered too often while only the last props update might have been useful and should have triggered a rendering of the component. In these cases, debouncing the rendering of a react component may be the only solution to improve performance.

react-debounce-render is a react component that will wrap any of your react components, persist the last props update that was received while discarding the previous ones, and only rendering the wrapped component when no new updates has been received in the last few milliseconds by default. Since the debounce function used under the hood is lodash's debounce, you may also pass in a few options such as the number of milliseconds to delay the render by, a maximum delay, or whether to call render on a leading or trailing edge of the timeout.

Usage:

Default usage:

import debounceRender from 'react-debounce-render';

const debouncedMyReactComponent = debounceRender(MyReactComponent);

// do whatever you want with the debounced component such as connecting to a redux store:
connect(state => {
    myProp: (state) => getProp(state)
})(debouncedMyReactComponent);

With options:

See lodash debounce for all options. Debounce render takes its parameters similarily to lodash debounce:

import debounceRender from 'react-debounce-render';

const debouncedMyReactComponent = debounceRender(MyReactComponent, 100, { leading: false });

Changelog

4.0.1 - APRIL 3 2018

  • Ensure that debounce is properly canceled when the component is unmounted which removes the "Warning: Can only update a mounted or mounting component." warning. Resolves Issue #5. Thanks @mjhm for the fix.

4.0.0 - NOVEMBER 20 2017

  • Move react to the peerDependencies in package.json and accept major versions greater than 15. Resolves Issue #4. Thanks @TheSharpieOne for raising the issue.

3.0.0 - AUGUST 16 2017

  • import debounceRender from 'react-debounce-render' should now consistently work. See Issue #2. Thanks @CameronAckermanSEL for raising the issue. As a result, using a destructuring assignment in the import statement (import { debounceRender } from 'react-debounce-render'') shouldn't accidentally work anymore which is a potential breaking change.

2.0.0 - JULY 31 2017

  • Module isn't built as standalone before being published to npm, resulting in a cleaner and lighter package. Also removes non lib related files from the package. See PR #1. Thanks @wbazant for the contribution.

1.0.0 - JUNE 25 2017

  • debounces a React component's render method()
  • includes e2e tests and documentation