lazy
lazy is a promise loader. It is used when you want to display something while a promise is loading, or to run a callback after a promise is resolved.
- Allows to display/run something, or nothing while a promise is resolving.
- Allows to run a callback when the promise resolves.
- Allows to get notified of errors, and display/run something, or nothing. If wanted, a retry function is given for retrying the promise.
- It will render what the promise returns. If the promise returns a function it can be used as Component(props).
# Attributes
name | type | description |
---|---|---|
fn | fn/promise | a function that returns a promise or a promise |
[options.onLoading] | any | renders something while the promise resolves |
[options.onLoaded] | Function | runs a callback after the promise resolves |
[options.onError] | any | (e: Error, retry: Function) => void) | renders something or runs a callback with the error object and a retry function as argument |
# When not to use lazy
Lazy is not needed unless you use one of its options. You may use a promise directly as follows.
# Usage
All the different uses of Lazy