The custom hook for data persisting into browser local storage so that after page reload they still will be present. The hook is multipurpose, you can simply copy them "as is" and utilize them for the most varied aims in your React application. The most lovely is that our custom hook posesses the same format as a useState hook if we do not consider that we need to pass additionaly "key" as a reference for our variable into browser local storage.
Don't forget to use the prefix "use" before each custom hook as a convention. Data into localStorage persists even after browser reload. If you are not willing such behavior you can use sessionStorage instead - the data will be saved only after page reload.