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"
139139
140140const loadCustomer = ({ customerId }) => fetch (` /api/customers/${ customerId} ` ).then (... )
141141
142- const AsyncCustomer = createInstance ({ promiseFn: loadCustomer })
142+ // createInstance takes a defaultProps object and a displayName (both optional)
143+ const AsyncCustomer = createInstance ({ promiseFn: loadCustomer }, " AsyncCustomer" )
143144
144145const MyComponent = () => (
145146 < AsyncCustomer customerId= " 123" >
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const isFunction = arg => typeof arg === "function"
66 * createInstance allows you to create instances of Async that are bound to a specific promise.
77 * A unique instance also uses its own React context for better nesting capability.
88 */
9- export const createInstance = ( defaultProps = { } ) => {
9+ export const createInstance = ( defaultProps = { } , displayName = "Async" ) => {
1010 const { Consumer, Provider } = React . createContext ( )
1111
1212 class Async extends React . Component {
@@ -203,6 +203,12 @@ export const createInstance = (defaultProps = {}) => {
203203 Async . Resolved = Resolved
204204 Async . Rejected = Rejected
205205
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+
206212 return Async
207213}
208214
You can’t perform that action at this time.
0 commit comments