FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Use Effect Once

10mins

Implement a function useEffectOnce(effect) that runs a provided callback function only a single time.

The function should:

  • Accept a function effect.
  • Execute the function once regardless of how many times it is called.
  • Ignore repeated invocations.

Examples

let count = 0; useEffectOnce(() => { count += 1; }); useEffectOnce(() => { count += 1; }); console.log(count); // 1

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests