Use the useState() hook with a function toinitial its value lazily. Creates a stateful value that is persisted to sessionStorage. Use a try...catch block and Storage.getItem() to try and get the value. If no value is found, use Storage.setItems() to store the value and use it as the initial state.
2 Comments