react-compiler eslint rules causing an error #2811
-
I just updated my Next app to NextJS 15, and after enabling the React Compiler ESlint rules, I am getting an error on my Zustand store. This could just be me, but I think this is a fairly minimal setup, so I don't think I've done anything wrong. The error below is occurring on the underlined section of the last line. Everything still works fine, so I'm just
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();
^^^^^^^^^^^^^^^^ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@maxwiseman would you mind sharing us a minimal repro on stackblitz? |
Beta Was this translation helpful? Give feedback.
-
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. 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),
},
),
);
export function useSettings() {
const { settings, setSettings } = useSettingsStore();
} |
Beta Was this translation helpful? Give feedback.
The eslint warning is correct.
☝️ You can't define a store inside a function.
It should b…