Skip to content

Commit d717409

Browse files
chore(release): 6.5.0 [skip ci]
# [6.5.0](v6.4.1...v6.5.0) (2026-09-04) ### Features * astro hook ([555159c](555159c))
1 parent 7b6c6d9 commit d717409

115 files changed

Lines changed: 815 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [6.5.0](https://github.com/asmyshlyaev177/state-in-url/compare/v6.4.1...v6.5.0) (2026-09-04)
2+
3+
4+
### Features
5+
6+
* astro hook ([555159c](https://github.com/asmyshlyaev177/state-in-url/commit/555159c8743b700cdbd2525fa8f48681cf1cd7ef))
7+
18
## [6.4.1](https://github.com/asmyshlyaev177/state-in-url/compare/v6.4.0...v6.4.1) (2026-08-21)
29

310

dist/astro/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useUrlState } from './useUrlState';

dist/astro/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";var e=require("./useUrlState/useUrlState.js");exports.useUrlState=e.useUrlState;

dist/astro/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import{useUrlState as t}from"./useUrlState/useUrlState.mjs";export{t as useUrlState};

dist/astro/useUrlState/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useUrlState';

dist/astro/useUrlState/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";var e=require("./useUrlState.js");exports.useUrlState=e.useUrlState;

dist/astro/useUrlState/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import{useUrlState as t}from"./useUrlState.mjs";export{t as useUrlState};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { type JSONCompatible } from '../../utils';
2+
/**
3+
* Astro hook, for React islands. Returns `urlState`, `setState`, and `setUrl` functions
4+
*
5+
* Astro has no client-side router by default, so the URL is written with
6+
* `window.history` and read back on back/forward, on this hook's own writes,
7+
* and on any other `pushState`/`replaceState`, `<ClientRouter />` included.
8+
* Islands on one page share the state.
9+
*
10+
* @param {JSONCompatible<T>} [defaultState] Fallback (default) values for state
11+
* @param {Object} params - Object with other parameters
12+
* @param {boolean} params.replace replace URL or push, default `true`
13+
* @param {?object} params.searchParams `Object.fromEntries(Astro.url.searchParams)`, passed as an island prop so the server render matches the URL
14+
* @returns {Object} [result] State and callbacks
15+
* @returns {Object} [result.urlState] - current state object
16+
* @returns {Function} [result.setUrl] - function to update state and url
17+
* @returns {Function} [result.setState] - function to update state only
18+
* @returns {Function} [result.reset] - function to reset state and url to default
19+
*
20+
* * Example:
21+
* ```ts
22+
* export const form = { name: '', age: 0 };
23+
* // island: <Form client:load searchParams={Object.fromEntries(Astro.url.searchParams)} />
24+
* const { urlState, setState, setUrl, reset } = useUrlState(form, { searchParams });
25+
*
26+
* setState({ name: 'test' });
27+
* setUrl({ name: 'test' }, { replace: false });
28+
* setUrl(curr => ({ ...curr, name: 'test' }));
29+
* // RESET state and url
30+
* setUrl((_curr, initialState) => initialState);
31+
* // Or
32+
* reset();
33+
* reset({ replace: false });
34+
* ```
35+
*
36+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/astro/useUrlState}
37+
*/
38+
export declare function useUrlState<T extends JSONCompatible>(defaultState: T, params?: Params): {
39+
/**
40+
* State object. Don't mutate directly, use `setState` or `setUrl`
41+
*/
42+
urlState: T;
43+
/**
44+
* * Example:
45+
* ```ts
46+
* setState({ name: 'test' });
47+
* // or
48+
* setState(curr => ({ ...curr, name: 'test' }) );
49+
* ```
50+
*
51+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/astro/useUrlState#setstate}
52+
*/
53+
setState: (value: Partial<T> | ((currState: T, initial: T) => T)) => void;
54+
/**
55+
* * Example:
56+
* ```ts
57+
* setUrl({ name: 'test' });
58+
* // or
59+
* setUrl((curr) => ({ ...curr, name: 'test' }), { replace: false } );
60+
* * Reset
61+
* setUrl((_curr, initialState) => initialState, { replace: false } );
62+
* ```
63+
*
64+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/astro/useUrlState#seturl}
65+
*/
66+
setUrl: (value?: Partial<T> | ((currState: T, initialState: T) => T), options?: Options) => void;
67+
/**
68+
* * Example:
69+
* ```ts
70+
* reset();
71+
* // or
72+
* reset({ replace: false })
73+
* ```
74+
*
75+
* * Docs {@link https://github.com/asmyshlyaev177/state-in-url/tree/master/packages/urlstate/astro/useUrlState#reset}
76+
*/
77+
reset: (options?: Options) => void;
78+
};
79+
export type Options = {
80+
replace?: boolean;
81+
};
82+
export type Params = {
83+
searchParams?: object;
84+
replace?: boolean;
85+
};

dist/astro/useUrlState/useUrlState.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import r from"react";import{parseSPObj as u}from"../../parseSPObj.mjs";import{useUrlStateBase as g}from"../../useUrlStateBase/useUrlStateBase.mjs";import{isSSR as k,filterUnknownParams as i,filterUnknownParamsClient as d,getSearch as m,routerHistory as C,getParams as h,subscribeToUrl as j}from"../../utils.mjs";function w(e,a){const{state:p,updateState:n,updateUrl:l,reset:c,getState:f,pendingUrlUpdate:S}=g(e,C,({parse:t})=>k?u(i(e,a?.searchParams),e):t(d(e,a?.searchParams||m())));const o=r.useCallback(()=>{if(S())return;n(i(e,u(Object.fromEntries(h(m()).entries()),e)))},[]);r.useEffect(()=>{o();return j(o)},[o]);const s=r.useMemo(()=>({replace:a?.replace??true}),[a?.replace]);const U=r.useCallback((t,P)=>l(t,{...s,...P}),[l,s]);const b=r.useCallback(t=>{c({...s,...t})},[c,s]);return{setState:n,setUrl:U,urlState:p,reset:b,getState:f}}export{w as useUrlState};

0 commit comments

Comments
 (0)