https://github.com/fabiospampinato/unstated-suspense
Suspend/unsuspend updates propagation from your containers.
https://github.com/fabiospampinato/unstated-suspense
hoc performance react suspend unstated
Last synced: about 1 year ago
JSON representation
Suspend/unsuspend updates propagation from your containers.
- Host: GitHub
- URL: https://github.com/fabiospampinato/unstated-suspense
- Owner: fabiospampinato
- License: mit
- Archived: true
- Created: 2018-09-25T09:23:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-10T17:05:19.000Z (over 7 years ago)
- Last Synced: 2024-09-24T18:05:32.260Z (almost 2 years ago)
- Topics: hoc, performance, react, suspend, unstated
- Language: TypeScript
- Homepage:
- Size: 24.4 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unstated Suspense
Suspend/unsuspend updates propagation from your containers.
It allows you to update the state multiple times while still triggering only one update of the components.
## Install
```sh
npm install --save unstated-suspense
```
## Usage
```ts
import {Container} from 'unstated-suspense';
class App extends Container {
state = { foo: 1, bar: 2 };
update () {
this.suspend (); // After calling `suspend` the components won't be notified of any state update
this.setFoo ( 11 ); // This will change the state, but it won't trigger an update of the components
this.setBar ( 12 ); // This will change the state, but it won't trigger an update of the components
this.unsuspend (); // Now updates are no longer suspended. If the state has been updated it will notify the components, just once (instead of twice in this particular case)
}
setFoo ( foo ) {
this.setState ({ foo });
}
setBar ( bar ) {
this.setState ({ bar });
}
}
```
**Note**: If you call `suspend` N times you should call `unsuspend` N time also to resume updates propagation.
## Related
- **[unstated-with-containers](https://github.com/fabiospampinato/unstated-with-containers)**: Higher-Order Component for subscribing to containers.
- **[unstated-connect2](https://github.com/fabiospampinato/unstated-connect2)**: Connect containers to components, without sacrificing performance.
- **[unstated-hmr](https://github.com/fabiospampinato/unstated-hmr)**: Preserve containers' states across Hot-Module-Replacements.
- **[unstated-compose](https://github.com/fabiospampinato/unstated-compose)**: Compose multiple containers into one.
- **[unstated-compose-suspense](https://github.com/fabiospampinato/unstated-compose-suspense)**: Add suspend/unsuspend support to `unstated-compose`.
- **[unstated-compose-suspense-middleware](https://github.com/fabiospampinato/unstated-compose-suspense-middleware)**: Add middlewares support to `unstated-compose-suspense`.
- **[unstated-suspense-autosuspend](https://github.com/fabiospampinato/unstated-suspense-autosuspend)**: Automatically use unstated-suspense on all your container's API methods.
- **[unstated-suspense-middleware](https://github.com/fabiospampinato/unstated-suspense-middleware)**: Add middlewares support to `unstated-suspense`.
## License
MIT © Fabio Spampinato