Implement a useStateWithReset hook that's similar to useState but with an additional reset function that resets the state to its initial value.

exportdefaultfunction Component() {
const [value, setValue, resetValue] = useStateWithReset(10);
return (
    <div>
      <div>Value: {value}</div>
      <input onChange={(e) => setValue(e.target.value)} />
      <button onClick={resetValue}>reset</button>
    </div>
  );
}

Arguments

Returns

The useStateWithReset hook should have the same return values as the useState hook, plus an additional function that resets the state to initialValue

My Solution

Editorial