FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Use Breakpoint

25mins

Implement a hook useBreakpoint(breakpoints) that returns the current breakpoint name depending on the window width.

The hook should:

  • Accept an object of breakpoints where keys are names and values are widths.
  • Return the name of the current breakpoint based on window.innerWidth.
  • Update the breakpoint name automatically on window resize.

Examples

const breakpoints = { mobile: 0, tablet: 768, desktop: 1024 }; useBreakpoint(breakpoints); // returns "mobile", "tablet", or "desktop" based on window width

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests