File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -268,7 +268,8 @@ Renders only while the deferred promise is still pending (not yet run).
268
268
269
269
#### Props
270
270
271
- - ` children ` {Function|Node} Function which receives props object or React node
271
+ - ` persist ` {boolean} Show until we have data, even while loading or when an error occurred. By default it hides as soon as the promise starts loading.
272
+ - ` children ` {Function|Node} Function which receives props object or React node.
272
273
273
274
#### Examples
274
275
@@ -281,7 +282,17 @@ Renders only while the deferred promise is still pending (not yet run).
281
282
```
282
283
283
284
``` js
284
- < Async .Pending > {({ run }) => < button onClick= {run}> Run< / button> }< / Async .Pending >
285
+ < Async .Pending persist>
286
+ {({ error, isLoading, run }) => (
287
+ < div>
288
+ < p> This text is only rendered while the promise has not resolved yet.< / p>
289
+ < button onClick= {run} disabled= {! isLoading}>
290
+ Run
291
+ < / button>
292
+ {error && < p> {error .message }< / p> }
293
+ < / div>
294
+ )}
295
+ < / Async .Pending >
285
296
```
286
297
287
298
## Acknowledgements
Original file line number Diff line number Diff line change @@ -113,12 +113,15 @@ export const createInstance = (defaultProps = {}) => {
113
113
/**
114
114
* Renders only when deferred promise is pending (not yet run).
115
115
*
116
+ * @prop {boolean } persist Show until we have data, even while loading or when an error occurred
116
117
* @prop {Function|Node } children Function (passing error and props) or React node
117
118
*/
118
- Async . Pending = ( { children } ) => (
119
+ Async . Pending = ( { children, persist } ) => (
119
120
< Consumer >
120
121
{ props => {
121
- if ( props . isLoading || props . data || props . error ) return null
122
+ if ( props . data !== undefined ) return null
123
+ if ( ! persist && props . isLoading ) return null
124
+ if ( ! persist && props . error !== undefined ) return null
122
125
return typeof children === "function" ? children ( props ) : children || null
123
126
} }
124
127
</ Consumer >
You can’t perform that action at this time.
0 commit comments