Skip to content

Commit

Permalink
❌ Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Romainlg29 committed Apr 26, 2024
1 parent 7eb79f4 commit 97f385d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ On the first "render" of the store, the middleware will check if the store alrea

If no tab is opened, the store will be created and will be shared as the "main" with the other tabs / windows.

_**Note:** It cannot be used in server components as it needs an environment that support the Broadcast Channel API_

#### New in v1.4.0

- You don't have to specify a channel name anymore. The channel name is now automatically generated. **However, I strongly recommend you to use it.**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-broadcast-ts",
"version": "1.4.4",
"version": "1.4.5",
"description": "Use the Broadcast Channel API in React easily with hooks or Zustand, and Typescript!",
"type": "module",
"types": "./dist/index.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ type SharedImpl = <T>(f: StateCreator<T, [], []>, options?: SharedOptions) => St
* @param options The options
*/
const sharedImpl: SharedImpl = (f, options) => (set, get, store) => {
if (typeof window === 'undefined') {
console.warn('BroadcastChannel is not supported in this environment. The store will not be shared.');
return f(set, get, store);
}

/**
* If BroadcastChannel is not supported, return the basic store
*/
Expand Down

0 comments on commit 97f385d

Please sign in to comment.