'How to set value in local storage while component unmounting

In my component, searchBar, i record user input in this.state.value. My task is to set this.state.value in localStorage.value while component unmounting(componentWillUnmount), plus after tab refreshed i must display localStorage.value in search bar. No hooks are allowed. Im really stuck, please help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source