Skip to content

Using the README examples it didn't work. #12

@AliReza99

Description

@AliReza99

Describe the bug
Using [email protected] and using the README examples it didn't work.

To Reproduce
using it just like the README example:

import { create } from "zustand";
import { syncTabs } from "zustand-sync-tabs";

type MyStore = {
	count: number;
	set: (n: number) => void;
};

export const useStore = create<MyStore>(
	syncTabs(
		set => ({
			count: 0,
			set: n => set({ count: n }),
		}),
		{ name: "my-channel" },
	),
);
//example.tsx

function Example() {
  return (
    <>
      <>Count: {useStore((s) => s.count)}</>
      <button
        onClick={() => {
          useStore.setState({ count: useStore.getState().count + 1 });
        }}
      >
        Add
      </button>
    </>
  );
}

and opening 2 tabs in nextjs v14.2.28 and clicking the "Add" button won't update the count in the other tab (also no error happens)

the same example tested with library: [email protected] and works properly

  • OS: Ubuntu 22
  • Browser: Chrome Version 133.0.6943.98 (Official Build) (64-bit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions