Using Hooks to manage application state
In this section we are going to learn about various community Hooks that help you manage application state. These Hooks are provided by useHooks.com, which is a collection of various useful Hooks packaged in a single library.
useLocalStorage
The Local Storage Hook allows you to store and retrieve data using the browser’s LocalStorage API. The LocalStorage API is a way to persistently store information in the user’s browser. We can use this to, for example, store information about the currently logged in user.
The useLocalStorage
function has the following signature:
const [data, saveData] = useLocalStorage(key, initialValue)
As we can see, the Local Storage Hook accepts a key (which is used to identify the data in local storage) and an initial value (which is a fallback used when there is no item with the given key in local storage). It then returns an API similar to the State Hook: The data itself, and a function...