1.1.0 • Published 5 years ago

trashable-react v1.1.0

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

trashable-react :put_litter_in_its_place:

npm David CircleCI npm

A Higher Order Component to make React Components garbage collectable when unmounted.

Learn more about garbage collection and trashable and why you should use it here.

Installation

npm install --save trashable-react

How to use

import makeComponentTrashable from 'trashable-react';

class Component extends React.Component {
    componentDidMount() {
        this.props.registerPromise(apiCall()).then(() => {
            // ...
        }).catch(() => {
            // ...
        });
    }
}

// Passes the registerPromise() function to Component
export default makeComponentTrashable(Component);

Gotchas

You need to register the promise before you add your then and catch handlers. Otherwise, you will not get the garbage collection benefits.

// Do this
const registeredPromise = registerPromise(promise);
registeredPromise.then(() => {});

// NOT this
const handledPromise = promise.then(() => {});
registerPromise(handledPromise);
1.1.0

5 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago