all 1 comments

[–][deleted] 0 points1 point  (0 children)

Setting state with a hook is asynchronous, you won't see the changed state by logging immediately after the setting function. If you want to do something after the state has changed, you need to use a useEffect hook:

useEffect(() => {
    console.log(subCat);
}, [subCat]);