π For those who have learned about useReducer, but still can't get when you should use intuitively
π I implemented toggle button by useState
const [showMenu, setShowMenu] = useState<boolean>(true) // when I want to show/hide toggle button setShowMenu(!showMenu)
π But I realised there is better way by useReducer
const [showMenu, toggleShowMenu] = useReducer((prev) => !prev, true) // when I want to show/hide toggle button, that's all! toggleShowMenu()
If you had like this experience "real life example of useReducer", make a comment please π
Top comments (0)