Skip to content

Commit

Permalink
Conform prepare release (#326)
Browse files Browse the repository at this point in the history
* docs: add changeset of `@location-state/conform`.

* docs: `useLocationKey`, `useLocationGetState` explain API docs.

* docs: fix changesets.

* docs: split changesets docs

* docs: fix `useLocationKey` / `useLocationGetState`

* docs: fix `useLocationGetState`/``useLocationKey` description word.

* chore: pnpm update version specify

---------

Co-authored-by: akfm.sato <01047245@CF0286.local>
  • Loading branch information
2 people authored and akfm.sato committed May 13, 2024
1 parent fb04cf9 commit 0e6a8c0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hungry-apples-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@location-state/conform": minor
---

Added `@location-state/conform` that is conform support package.
5 changes: 5 additions & 0 deletions .changeset/stale-spoons-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@location-state/core": minor
---

Added `useLocationGetState`/`useLocationKey` to `@location-state/core`.
69 changes: 68 additions & 1 deletion packages/location-state-core/docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
- [type `Refine`](#type-Refine)
- [function `useLocationState`](#function-useLocationState)
- [function `useLocationStateValue`](#function-useLocationStateValue)
- [function `useLocationGetState`](#function-useLocationGetState)
- [function `useLocationSetState`](#function-useLocationSetState)
- [function `useLocationKey`](#function-useLocationKey)
- [Provider](#Provider)
- [component `<LocationStateProvider>`](#component-LocationStateProvider)
- [function `createDefaultStores`](#function-createDefaultStores)
Expand Down Expand Up @@ -41,7 +43,7 @@ type LocationStateDefinition<
Common options for state hooks.

> **Warning**
> State hooks evaluates this option only once at the first rendering.**Passing different values at re-rendering is not applied.**
> State hooks evaluates this option only once at the first rendering. **Passing different values at re-rendering is not applied.**
#### Type Parameters

Expand Down Expand Up @@ -179,6 +181,45 @@ const count = useLocationStateValue({
});
```

### function `useLocationGetState`

```ts
type GetState<T> = () => T;

declare const useLocationGetState: <T>(
definition: LocationStateDefinition<T, DefaultStoreName>,
) => GetState<T>;
```

Allows getting of the state associated with the current history location from a specified `Store`. This hooks will **not re-render** the component if there is a change in the state.

#### Type Parameters

- `T`: Type of state.

#### Parameters

- `definition`: See [`LocationStateDefinition`](#type-locationstatedefinition).

#### Returns

Returns the callback function to get state. It can be used in the `useEffect` hook, event handler, etc.

#### Example

```ts
const getCount = useLocationGetState({
name: "count",
defaultValue: 0,
storeName: "session",
});

useEffect(() => {
const count = getCount();
// ...
}, [getCount]);
```

### function `useLocationSetState`

```ts
Expand Down Expand Up @@ -213,6 +254,32 @@ const setCount = useLocationSetState({
});
```

### function `useLocationKey`

```ts
declare const useLocationKey: ({ serverDefault, clientDefault, }?: {
serverDefault?: string | undefined;
clientDefault?: string | undefined;
} | undefined) => string | undefined;
```

Returns the key associated with the current history location from the `Syncer`.

#### Parameters

- `serverDefault`: Key on the server. This key is used when server side and client hydration. If not specified, `undefined` is used.
- `clientDefault`: Default key when key is not available. If not specified, `undefined` is used.

#### Returns

Returns the key associated with the current history location.

#### Example

```ts
const locationKey = useLocationKey();
```

## Provider

### component `<LocationStateProvider>`
Expand Down

0 comments on commit 0e6a8c0

Please sign in to comment.