File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,8 @@ import { createInstance } from "react-async"
139
139
140
140
const loadCustomer = ({ customerId }) => fetch (` /api/customers/${ customerId} ` ).then (... )
141
141
142
- const AsyncCustomer = createInstance ({ promiseFn: loadCustomer })
142
+ // createInstance takes a defaultProps object and a displayName (both optional)
143
+ const AsyncCustomer = createInstance ({ promiseFn: loadCustomer }, " AsyncCustomer" )
143
144
144
145
const MyComponent = () => (
145
146
< AsyncCustomer customerId= " 123" >
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const isFunction = arg => typeof arg === "function"
6
6
* createInstance allows you to create instances of Async that are bound to a specific promise.
7
7
* A unique instance also uses its own React context for better nesting capability.
8
8
*/
9
- export const createInstance = ( defaultProps = { } ) => {
9
+ export const createInstance = ( defaultProps = { } , displayName = "Async" ) => {
10
10
const { Consumer, Provider } = React . createContext ( )
11
11
12
12
class Async extends React . Component {
@@ -203,6 +203,12 @@ export const createInstance = (defaultProps = {}) => {
203
203
Async . Resolved = Resolved
204
204
Async . Rejected = Rejected
205
205
206
+ Async . displayName = displayName
207
+ Async . Pending . displayName = `${ displayName } .Pending`
208
+ Async . Loading . displayName = `${ displayName } .Loading`
209
+ Async . Resolved . displayName = `${ displayName } .Resolved`
210
+ Async . Rejected . displayName = `${ displayName } .Rejected`
211
+
206
212
return Async
207
213
}
208
214
You can’t perform that action at this time.
0 commit comments