You can organize your code better by separating the state management into its own module. Here’s how…