@sanity/react-loader
Advanced tools
Comparing version 0.6.0-pink-lizard to 0.7.0-pink-lizard
@@ -9,2 +9,21 @@ # Changelog | ||
## [0.7.0-pink-lizard](https://github.com/sanity-io/visual-editing/compare/react-loader-v0.6.0-pink-lizard...react-loader-v0.7.0-pink-lizard) (2023-11-08) | ||
### ⚠ BREAKING CHANGES | ||
* `initialData` and `initialSourceMap` are now grouped by `initial` | ||
### Bug Fixes | ||
* `initialData` and `initialSourceMap` are now grouped by `initial` ([30f8cfd](https://github.com/sanity-io/visual-editing/commit/30f8cfdf284c940e5589820e1c72b5c50da17cbd)) | ||
* **deps:** update dependency @sanity/client to v6.8.0-pink-lizard.9 ([#295](https://github.com/sanity-io/visual-editing/issues/295)) ([6335f36](https://github.com/sanity-io/visual-editing/commit/6335f36c0c5324499ccbd42256e3a5d317e3a709)) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* dependencies | ||
* @sanity/core-loader bumped to 0.7.0-pink-lizard | ||
## [0.6.0-pink-lizard](https://github.com/sanity-io/visual-editing/compare/react-loader-v0.5.3-pink-lizard...react-loader-v0.6.0-pink-lizard) (2023-11-08) | ||
@@ -11,0 +30,0 @@ |
@@ -14,7 +14,7 @@ import type { ContentSourceMap } from '@sanity/client' | ||
export declare interface QueryStore { | ||
query: <Response>( | ||
query: <QueryResponseResult>( | ||
query: string, | ||
params?: QueryParams, | ||
) => Promise<{ | ||
data: Response | ||
data: QueryResponseResult | ||
sourceMap: ContentSourceMap | undefined | ||
@@ -29,11 +29,32 @@ }> | ||
export declare type UseQueryHook = <Response = unknown, Error = unknown>( | ||
export declare type UseQueryHook = < | ||
QueryResponseResult = unknown, | ||
QueryResponseError = unknown, | ||
>( | ||
query: string, | ||
params?: QueryParams, | ||
options?: UseQueryOptions<Response>, | ||
) => QueryStoreState<Response, Error> | ||
options?: UseQueryOptions<QueryResponseResult>, | ||
) => QueryStoreState<QueryResponseResult, QueryResponseError> | ||
export declare interface UseQueryOptions<Response = unknown> { | ||
initialData?: Response | ||
initialSourceMap?: ContentSourceMap | ||
export declare interface UseQueryOptions<QueryResponseResult = unknown> { | ||
/** | ||
* Initial `data` and `sourceMap`, used with SSR hydration and is required if `ssr: true` | ||
* and an optional speed optimization if `ssr: false`. | ||
* It's recommended to set `initial` to the return value of `query()`. | ||
* @example | ||
* ```ts | ||
* const queryAuthor = `*[_type == "author" && slug.current == $slug][0]` | ||
* export const getServerSideProps = async ({params}) => { | ||
* const initial = await query<AuhthorType>(queryAuthor, params) | ||
* return { props: { params, initial } } | ||
* } | ||
* export default function Page({params, initial}) { | ||
* const {data} = useQuery<AuthorType>(queryAuthor, params, {initial}) | ||
* } | ||
* ``` | ||
*/ | ||
initial?: { | ||
data: QueryResponseResult | ||
sourceMap: ContentSourceMap | undefined | ||
} | ||
startTransition?: TransitionFunction | ||
@@ -40,0 +61,0 @@ } |
@@ -19,19 +19,16 @@ import { createQueryStore as createQueryStore$1 } from '@sanity/core-loader'; | ||
const { | ||
initialData: _initialData, | ||
initialSourceMap: _initialSourceMap, | ||
startTransition: startTransition$1 = startTransition | ||
} = options2; | ||
const [initialData] = useState(() => _initialData); | ||
const [initialSourceMap] = useState(() => _initialSourceMap); | ||
const [initial] = useState(() => options2.initial); | ||
const $params = useMemo(() => JSON.stringify(params), [params]); | ||
const [snapshot, setSnapshot] = useState(() => ({ | ||
...initialFetch, | ||
data: initialData, | ||
sourceMap: initialSourceMap | ||
data: initial?.data, | ||
sourceMap: initial?.sourceMap | ||
})); | ||
useEffect(() => { | ||
const fetcher = createFetcherStore(query2, JSON.parse($params), initialData, initialSourceMap); | ||
const fetcher = createFetcherStore(query2, JSON.parse($params), initial); | ||
const unlisten = fetcher.listen(snapshot2 => startTransition$1(() => setSnapshot(snapshot2))); | ||
return () => unlisten(); | ||
}, [$params, initialData, initialSourceMap, query2, startTransition$1]); | ||
}, [$params, initial, query2, startTransition$1]); | ||
return snapshot; | ||
@@ -38,0 +35,0 @@ }; |
{ | ||
"name": "@sanity/react-loader", | ||
"version": "0.6.0-pink-lizard", | ||
"version": "0.7.0-pink-lizard", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/react-loader#readme", | ||
@@ -123,6 +123,6 @@ "bugs": { | ||
"dependencies": { | ||
"@sanity/core-loader": "0.6.0-pink-lizard" | ||
"@sanity/core-loader": "0.7.0-pink-lizard" | ||
}, | ||
"devDependencies": { | ||
"@sanity/client": "6.8.0-pink-lizard.8", | ||
"@sanity/client": "6.8.0-pink-lizard.9", | ||
"@sanity/pkg-utils": "^3.2.3", | ||
@@ -142,3 +142,3 @@ "@types/react": "^18.2.37", | ||
"peerDependencies": { | ||
"@sanity/client": "6.8.0-pink-lizard.8", | ||
"@sanity/client": "6.8.0-pink-lizard.9", | ||
"react": "^18.2.0" | ||
@@ -145,0 +145,0 @@ }, |
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
375875
1546
+ Added@sanity/client@6.8.0-pink-lizard.9(transitive)
+ Added@sanity/core-loader@0.7.0-pink-lizard(transitive)
+ Added@sanity/groq-store@5.2.4-pink-lizard(transitive)
- Removed@sanity/client@6.8.0-pink-lizard.8(transitive)
- Removed@sanity/core-loader@0.6.0-pink-lizard(transitive)
- Removed@sanity/groq-store@5.2.3-pink-lizard(transitive)