I'm creating some buttons in React that trigger a state change from one to the next. Some of my buttons have three states, represented by enums. These three states should be set in consecutive order. When the last value is reached, the next operation should set the state back to the first value of the enumeration again. What's the clever way to accomplish this?
import { create } from 'zustand' import { devtools, persist, createJSONStorage } from 'zustand/middleware' import { BackgroundVariant as Background } from 'reactflow'; function nextBackground(background: Background): Background { switch (background) { case Background.Dots: return Background.Cross; case Background.Cross: return Background.Lines; default: return Background.Dots; }; }; interface MenuState { background: Background; toggleBackground: () => void; } export const useMenuStore = create<MenuState>()( devtools( persist( (set) => ({ background: Background.Dots, toggleBackground: () => set((state) => ({ background: nextBackground(state.background) })) }), { name: 'menu-storage', storage: createJSONStorage(() => localStorage), } ) ) );
主观臆断是什么意思hcv9jop1ns1r.cn | 一什么水缸hcv7jop6ns0r.cn | tvoc是什么意思hcv7jop9ns1r.cn | 安痛定又叫什么名字hcv9jop5ns6r.cn | 痤疮用什么药治最好效果最快hcv9jop7ns3r.cn |
喝蒲公英茶有什么作用hcv7jop9ns1r.cn | 支气管扩张是什么原因引起hcv9jop6ns5r.cn | 胃消化不良吃什么药hcv8jop2ns1r.cn | 文采是什么意思hcv7jop9ns2r.cn | 诺迪康胶囊治什么病hcv8jop2ns7r.cn |
子宫切除有什么影响hcv7jop7ns0r.cn | 名垂千古是什么意思hcv7jop7ns1r.cn | 发心是什么意思hcv9jop5ns3r.cn | 自学成才是什么意思hcv8jop6ns8r.cn | 6月19日是什么节日weuuu.com |
仰卧起坐是什么现象hcv9jop1ns9r.cn | 权志龙的团队叫什么hcv7jop9ns0r.cn | 狐臭看什么科hcv8jop7ns7r.cn | 易胖体质是什么原因造成的hcv9jop6ns6r.cn | 腰肌劳损看什么科sanhestory.com |
Here is an example of a function that accepts any enumeration and will return the next value or the first value if it is the last value: