FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Use State With Reset

10mins

Implement a function useStateWithReset(initialValue) that behaves like a normal state handler but provides an additional reset function.

The function should:

  • Accept an initial value.
  • Return an object containing:
    • value: current state value.
    • setValue: function to update the state.
    • reset: function to reset the state back to the initial value.

Example

const state = useStateWithReset(5); state.value; // 5 state.setValue(10); state.value; // 10 state.reset(); state.value; // 5

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests