Frontend
450 bites tagged Frontend — interview questions with model answers, and 60-second explainers.
Implement a protected /dashboard route in React Router
Tests declarative route guards versus imperative redirects in React Router 7. Strong answer: reusable ProtectedRoute wrapper with Navigate replace, auth state above Routes, and role checks.
Primary roles of BrowserRouter, Routes, and Route, and basic route setup
Tests v6 routing hierarchy. BrowserRouter provides history; Routes picks one match; Route maps path to element. Wrap Routes in BrowserRouter with nested Route elements for / and /about. Red flag: omitting the router or confusing Routes with Switch.
Where and how to import global stylesheets in Next.js
This tests Next.js style entry points. In the App Router, import global CSS in the root layout.js; in the Pages Router, import it in _app.js. Never import global styles inside pages or components, since Next.js restricts global CSS to root-level files.
Use useContext to provide theme state without prop drilling
This tests global state sharing without prop drilling. A strong answer uses createContext and a Provider with useState at the app root, then calls useContext in nested components. Red flag: ignoring re-render costs or placing the Provider too deep.
What is a custom hook? Write a simple useToggle example.
What it tests: Whether you see hooks as stateful logic extraction. Outline: Define a use-prefixed function calling hooks; write useToggle with useState and callback; explain extraction vs duplication. Red flag: Helpers without hooks or missing use prefix.
Write the React.createElement() equivalent for this JSX
Tests JSX-to-JS compilation mechanics. Answer: createElement('a', {href: '/home', className: 'link'}, 'Go Home'). Children must be the third argument, not inside props. Red flag: nesting children in props or using an unquoted tag variable.
Describe two patterns for conditional rendering in JSX
First, early return with if/else for branches; second, ternary or logical AND inside JSX for inline toggles. Whether you know React conditional rendering. Reaching for useState or useEffect when simple JS suffices.
What is the purpose of React's key prop and index key risks?
This tests React reconciliation. Keys give stable identity to match components across renders and preserve state. Indices break on reorder or delete, causing state bugs. A red flag: saying keys are only for performance or indices are harmless.
What are the two main ways to define a component in React?
Tests fluency in function and class syntax. Outline: show a function returning an h1; show a class with render() returning an h1; note functions are the React 19 default. Red flag: offering arrow vs function declaration as the two ways, or omitting render().
Explain props in React and how parent components pass data to children
Define props as the single object argument; show destructuring; stress immutability and downward flow; note defaults. Your grasp of props as the read-only, one-way parent-to-child interface.
Accessible React Forms: Labels, Focus, and Errors
Accessible React forms need real labels, keyboard focus, and error announcements, not just ARIA. Screen reader users must perceive inputs and validation without visual cues. The common footgun is placeholder text or divs instead of label elements with htmlFor.
BrowserRouter: Real URLs in React SPAs
BrowserRouter turns the address bar into a client-side navigation system, using real URLs without reloads. It is the default choice for SPAs that need shareable links.
BEM: Self-Documenting CSS Class Names
BEM turns classes into a mini filesystem: Block__Element--Modifier. It prevents CSS collisions in large React codebases where many teams share a global stylesheet. The footgun is turning every nested tag into an element and creating comically long names.
Rules of Hooks: Call Order Is Sacred
Hook calls must keep the same order every render because React maps them to state by array index. Only call hooks at the top level of React functions. Break the order and React desyncs, producing stale state or crashes.
KPIs for a new registration form and technical instrumentation
Tests pairing outcomes with instrumentation. Pick a conversion KPI and a field-level friction KPI, then explain client-side events correlated with server logs while scrubbing PII. Red flag: relying solely on frontend analytics or vanity metrics.
How would you implement a timezone-safe, tamper-proof offer countdown?
Tests distrust of the client and server-side UTC enforcement. Outline: server owns canonical end time; client syncs clock offset to render remaining time; checkout re-validates expiry. Red flag: using local Date.now or localStorage.
How would you track a 'Sign Up' button click end-to-end?
It tests your ability to instrument a custom event and validate the pipeline. Attach a gtag listener to the button, fire a sign_up_click event, then confirm the hit in GA4 DebugView or real-time reports.
How would you structure a flexible Card component API?
Tests composition-over-configuration thinking in design systems. A strong answer uses compound components or slots so consumers reorder or omit title, image, and body freely without prop drilling. Red flag: rigid boolean props that freeze layout order.
Two strategies to prevent style leakage in reusable components and their trade-offs
This tests style encapsulation in design systems. A strong answer contrasts Shadow DOM, which fully isolates CSS via a shadow root, with scoped naming like BEM or CSS Modules. Red flag: proposing global resets or !important as a solution.
Implement a typographic scale using design tokens and accessible properties
Token-driven typography and accessibility. Start with base size (14-16px) and ratio token, compute sizes, then bundle font-size with line-height, letter-spacing, weight, and family in composite tokens. Red flag: ignoring line-height, spacing, or composites.
What are the main benefits of consuming a design system?
Cite tokens for theming, isolated components, live docs, and designer collaboration. whether you see a design system as more than a UI kit and tie tokens to velocity. calling it just a CSS framework and ignoring tokens.
What is a design system and its primary engineering components?
Tests if you treat design systems as engineering infrastructure, not just UI kits. Strong answers cite reusable coded components, design tokens, documentation, and governance as the core. Red flag: calling it just a component library or style guide.
Scoped Theming: Local Overrides Without Global Leaks
Scoped theming is sunglasses for a UI subtree: it swaps tokens for one section without touching the global page. Use it for a dark-mode dashboard or white-label widget inside a light app, but avoid deep nesting or you will fight invisible inheritance chains.
Token Aliasing: Theme by Role, Not Value
Token aliasing names a color by its job, not its hex, so you swap the underlying value per theme. One library supports light mode, dark mode, or multiple brands without code changes. The footgun is deep alias chains that hide which primitive value renders.
Get Frontend bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.