Creating a Debounced History State Hook
We are now going to create a slightly more advanced Hook for debounced history state functionality. In Chapter 10, Using Community Hooks, we learned about the History State Hook, which allowed us to implement undo/redo functionality in the CreatePost component. We then used a Debounce Hook to avoid storing every single change in the history, allowing us to undo/redo larger parts of the text instead of a single character at a time. Now, we are going to extract this combined functionality into a custom Debounced History State Hook.
While this functionality is currently only used in one component, it is a generic feature that could be used in other components. Also, abstracting this functionality into a separate Hook allows us to keep the CreatePost component code clean and concise.
Creating the Debounced History State Hook
Let’s now get started extracting the code from the CreatePost component into a Debounced History State...