Skip to content

Commit a28afc2

Browse files
committed
✏️ copy new section from use-local-storage-state
1 parent 89ce583 commit a28afc2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ export default function Todos() {
125125

126126
</details>
127127

128+
<details>
129+
<summary>Why does my component re-renders twice?</summary>
130+
<p></p>
131+
132+
If you are hydrating your component (for example, if you are using Next.js), your component might re-render twice. This is behavior specific to React and not to this library. It's caused by the `useSyncExternalStore()` hook. There is no workaround. This has been discussed in the issues: https://github.com/astoilkov/use-local-storage-state/issues/56.
133+
134+
If you want to know if you are currently rendering the server value you can use this helper function:
135+
```ts
136+
function useIsServerRender() {
137+
return useSyncExternalStore(() => {
138+
return () => {}
139+
}, () => false, () => true)
140+
}
141+
```
142+
143+
</details>
144+
128145
## API
129146

130147
### `useSessionStorageState(key: string, options?: SessionStorageOptions)`

0 commit comments

Comments
 (0)