@shopify/react-async
Advanced tools
Comparing version 0.0.0-snapshot-20221129224804 to 0.0.0-snapshot-20230203161211
@@ -7,3 +7,2 @@ 'use strict'; | ||
var reactEffect = require('@shopify/react-effect'); | ||
var reactHooks = require('@shopify/react-hooks'); | ||
var assets = require('./context/assets.js'); | ||
@@ -30,3 +29,2 @@ | ||
const [value, setValue] = React.useState(() => immediate || typeof window !== 'undefined' ? resolver.resolved : null); | ||
const mounted = reactHooks.useMountedRef(); | ||
const load = React.useCallback(async () => { | ||
@@ -38,23 +36,16 @@ if (value != null) { | ||
try { | ||
const resolved = await resolver.resolve(); | ||
const resolved = await resolver.resolve(); // It's important to use the function form of setValue here. | ||
// Resolved is going to be a function in most cases, since it's | ||
// a React component. If you do not set it using the function form, | ||
// React treats the component as the function that returns state, | ||
// so it sets state with the result of manually calling the component | ||
// (so, usually JSX). | ||
if (mounted.current) { | ||
// It's important to use the function form of setValue here. | ||
// Resolved is going to be a function in most cases, since it's | ||
// a React component. If you do not set it using the function form, | ||
// React treats the component as the function that returns state, | ||
// so it sets state with the result of manually calling the component | ||
// (so, usually JSX). | ||
setValue(() => resolved); | ||
} | ||
setValue(() => resolved); | ||
return resolved; | ||
} catch (error) { | ||
if (mounted.current) { | ||
setValue(error); | ||
} | ||
setValue(error); | ||
return error; | ||
} | ||
}, [mounted, resolver, value]); | ||
}, [resolver, value]); | ||
const { | ||
@@ -61,0 +52,0 @@ id |
import { Resolver } from '@shopify/async'; | ||
import { IfAllOptionalKeys, NoInfer } from '@shopify/useful-types'; | ||
import { AssetTiming, AsyncComponentType } from './types'; | ||
export type Preloadable<PreloadOptions extends object> = Pick<AsyncComponentType<any, any, PreloadOptions, any, any>, 'usePreload'>; | ||
export type Prefetchable<PrefetchOptions extends object> = Pick<AsyncComponentType<any, any, any, PrefetchOptions, any>, 'usePrefetch'>; | ||
export type KeepFreshable<KeepFreshOptions extends object> = Pick<AsyncComponentType<any, any, any, any, KeepFreshOptions>, 'useKeepFresh'>; | ||
export declare type Preloadable<PreloadOptions extends object> = Pick<AsyncComponentType<any, any, PreloadOptions, any, any>, 'usePreload'>; | ||
export declare type Prefetchable<PrefetchOptions extends object> = Pick<AsyncComponentType<any, any, any, PrefetchOptions, any>, 'usePrefetch'>; | ||
export declare type KeepFreshable<KeepFreshOptions extends object> = Pick<AsyncComponentType<any, any, any, any, KeepFreshOptions>, 'useKeepFresh'>; | ||
export declare function usePreload<PreloadOptions extends object>(...args: IfAllOptionalKeys<PreloadOptions, [ | ||
@@ -8,0 +8,0 @@ Preloadable<PreloadOptions>, |
@@ -34,5 +34,5 @@ import { ReactElement } from 'react'; | ||
} | ||
export type PreloadOptions<T> = T extends AsyncHookTarget<any, infer U, any, any> ? U : never; | ||
export type PrefetchOptions<T> = T extends AsyncHookTarget<any, any, infer U, any> ? U : never; | ||
export type KeepFreshOptions<T> = T extends AsyncHookTarget<any, any, any, infer U> ? U : never; | ||
export declare type PreloadOptions<T> = T extends AsyncHookTarget<any, infer U, any, any> ? U : never; | ||
export declare type PrefetchOptions<T> = T extends AsyncHookTarget<any, any, infer U, any> ? U : never; | ||
export declare type KeepFreshOptions<T> = T extends AsyncHookTarget<any, any, any, infer U> ? U : never; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@shopify/react-async", | ||
"version": "0.0.0-snapshot-20221129224804", | ||
"version": "0.0.0-snapshot-20230203161211", | ||
"license": "MIT", | ||
@@ -36,5 +36,4 @@ "description": "Tools for creating powerful, asynchronously-loaded React components", | ||
"@shopify/react-effect": "^5.0.2", | ||
"@shopify/react-hooks": "^3.0.2", | ||
"@shopify/react-hydrate": "^3.0.6", | ||
"@shopify/react-idle": "0.0.0-snapshot-20221129224804", | ||
"@shopify/react-idle": "^3.0.3", | ||
"@shopify/react-intersection-observer": "^4.0.2", | ||
@@ -41,0 +40,0 @@ "@shopify/useful-types": "^5.1.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
7
109262
1774
+ Added@shopify/react-idle@3.2.0(transitive)
- Removed@shopify/react-hooks@^3.0.2
- Removed@shopify/react-hooks@3.2.0(transitive)
- Removed@shopify/react-idle@0.0.0-snapshot-20221129224804(transitive)
Updated@shopify/react-idle@^3.0.3