Correct way to represpen close state of controlled Navigation Menu #2124
-
Not workThe type for const [openingMenu, setOpeningMenu] = React.useState<string>()
// ^ string | undefined
return <NavigationMenu.Root
value={openingMenu}
onValueChange={setOpeningMenu}
/> But since it is controlled, for react, WorkI'm currently mark close state as empty string and it seems to work. const [openingMenu, setOpeningMenu] = React.useState('')
// close NavigationMenuby
setOpeningMenu('') My Question
Some clips for the sample codebandicam.2023-05-02.17-20-00-368.mp4bandicam.2023-05-02.17-20-08-891.mp4bandicam.2023-05-02.17-20-20-553.mp4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes that's correct. Controlling it and setting it back to |
Beta Was this translation helpful? Give feedback.
Yes that's correct. Controlling it and setting it back to
undefined
is essentially trying to set it back to "uncontrolled" so should be avoided. The same is true for any component in React (ie. the same is true with nativeinput
for example and React will actually warn you if you do this).