Skip to content

react-compiler eslint rules causing an error #2811

Answered by dai-shi
maxwiseman asked this question in Q&A
Discussion options

You must be logged in to vote

The eslint warning is correct.

export function useSettings() {
  type UserSettings = {
    colorScheme: "system" | "light" | "dark";
  };
  const useSettingsStore = create<{
    settings: UserSettings;
    setSettings: (arg0: UserSettings) => void;
  }>()(
    persist(
      (set) => ({
        settings: {
          colorScheme: "system",
        } as UserSettings,
        setSettings: (settings: UserSettings) => {
          set({ settings });
        },
      }),
      {
        name: "settings",
        storage: createJSONStorage(() => localStorage),
      },
    ),
  );

  const { settings, setSettings } = useSettingsStore();
}

☝️ You can't define a store inside a function.
It should b…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@maxwiseman
Comment options

Comment options

You must be logged in to vote
1 reply
@maxwiseman
Comment options

Answer selected by maxwiseman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants