DEV Community

Discussion on: How to manage state in React apps with useReducer and useContext hooks

Collapse
 
devjacks_91 profile image
devjacks

Take it a step further! Bring the useContext logic into it's own custom hook. That way you don't have to import useContext and ExpenseContext in each component. I like to use

const { amount, setAmount, name, setName} = useUI()

Makes for much cleaner code :)

Collapse
 
amanhimself profile image
Aman Mittal

Thats a great suggestion. Yeah using a custom hook does sound pragmatic in an app’s scenario.