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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-defer

v0.0.5

Published

React Mixin to safely defer methods across a components lifecycle.

Readme

react-defer

Just a quick mixin to avoid headaches and componentWillMount/componentWillUnmount boilerplate when dealing with deferreds and intervals in components that get unmounted. Supports executing any deferred inline function or auto-defers a method. Also works with intervals.

The enforced semantics are the following: "Execute the function if the component is still mounted by the time it kicks in. Otherwise, silently discard it altogether and clean up after yourself."

In particular, if you chain deferrals, you may end up calling deferred callbacks after the component has unmounted (for exemple when a Promise of whatever is resolved). Wrap the callback in Defer.IfMounted and if this happens, it will silently fail.

Examples

var Defer = require("react-defer");

React.createClass({
	mixins: [DeferMixin],
	alwaysDeferThisMethod: Defer.Deferred(function() {
		this.setState({
			hello: "world",
		});
	}),
	alwaysRAFThisMethod: Defer.DeferredAnimationFrame(function() {
		somethingThatAlwaysNeedsToBeDoneInNextAF();
	}),
	nonDeferredMethod: function() {
		this.setState({
			sup: "bro",
		});
	},
	someOtherMethod: function() {
		this.defer(this.nonDeferredMethod)("some", "args");
	},
	someInterfacingMethod: function() {
		this.giveMeSomthingReturningAPromise().then(Defer.IfMounted(this.nonDeferredMethod));
	},
}
});

API

Mixin.timeout(fn: function, delay: Number): function

Returns a function that will be deferred by delay upon calling (like a currified setTimeout). If the components unmounts before the timeout expires, then the timeout is silently cleared. The returned function itself returns an Object with a single method, clear, which clears the underlying timeout manually.

Mixin.defer(fn: function): function

Shortcut to timeout(fn, 1). Useful to setState in the next rendering cycle, althought this might very well be code smell.

Mixin.interval(fn, function, period: Number): function

Similar to timeout but instead sets an interval.

Mixin.deferAnimationFrame(fn: function)

Similar to defer but instead defers to the next animation frame. Uses the raf npm package requestAnimationFrame polyfill.

Mixin.intervalAnimationFrame(fn: function)

Similar to interval but instead ticks on each next animation frame. Uses the raf npm package requestAnimationFrame polyfill.

IfMounted(fn: function): function

Returns a function with the same this context that will silently fail if it is invoked after the component has unmounted.

Deferred(fn: function): function

Returns a function with the same this context that is deferred. Useful for defining methods that are always called deferred. Code smell warning, you should know whether your function call is going to be deferred or not.

DeferredAnimationFrame(fn: function): function

Similar to Deferred but instead defers to the next animation frame. Uses the raf npm package requestAnimationFrame polyfill.

License

MIT Elie Rotenberg [email protected]