Quick reference for frontend interview questions (Angular, React, JavaScript) organized by company and topic. Click on any question to expand details.
What is React Query? - React
Problem Statement
What is React Query and what problem does it solve?
Definition
React Query (now TanStack Query) is a data-fetching / server-state management library for React. It handles fetching, caching, and syncing data from an API — so you stop hand-rolling useEffect + useState fetch logic.
Why Not Just Redux/Context?
Redux/Context manage client state (UI state you own). React Query manages server state — data that lives on a server, can go stale, and needs refetching. Mixing the two leads to a lot of boilerplate (loading/error flags, manual cache invalidation).
Key Features
- Caching: dedupes identical requests, serves cached data instantly while refetching in the background (stale-while-revalidate)
- Automatic refetching: on window focus, network reconnect, or interval
- Retries: failed requests retry automatically with backoff
- Pagination / Infinite queries: built-in helpers (
useInfiniteQuery) - Mutations:
useMutationfor POST/PUT/DELETE with optimistic updates
Basic Usage
function Todos() {
const { data, isLoading, error } = useQuery({
queryKey: ['todos'],
queryFn: () => fetch('/api/todos').then(res => res.json()),
});
if (isLoading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return <ul>{data.map(todo => <li key={todo.id}>{todo.title}</li>)}</ul>;
}
Companies: Nike
Fetch API Data in React with useEffect + useState - React | TypeScript
Problem Statement
Fetch a user’s data from an API and render it, using React hooks and TypeScript. A common warm-up coding question — it’s really testing async handling, hook usage, and typing discipline.
API: GET https://jsonplaceholder.typicode.com/users/1
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org"
}
Common Mistakes Under Interview Pressure
- Calling
fetch()withoutawaitor.json()— you end up storing the unresolvedPromise/Responseobject, not the data - Declaring an
interfaceinside the component body instead of at module level - Typing
useStateasany, losing all type safety - Malformed
useEffect(missing arrow function, stray parens)
Corrected Solution
interface User {
id: number;
name: string;
username: string;
email: string;
phone: string;
website: string;
}
function App() {
const [user, setUser] = useState<User | null>(null);
const getUserData = async () => {
const response = await fetch("https://jsonplaceholder.typicode.com/users/1");
const data: User = await response.json();
setUser(data);
};
useEffect(() => {
getUserData();
}, []);
return (
<div className="App">
<h2>User Data</h2>
{user ? (
<div>
<p><strong>Name: {user.name}</strong></p>
<p><strong>Website: {user.website}</strong></p>
<p><strong>Email: {user.email}</strong></p>
<p><strong>Phone: {user.phone}</strong></p>
</div>
) : (
<div>No data</div>
)}
</div>
);
}
Key Points
interfaceat module level — not redeclared on every render inside the componentuseState<User | null>instead ofany— get compile-time safety on every field you accessawaitboth the fetch and.json()—fetch()only resolves the response headers, the body still needs a second async step- Empty dependency array
[]— runs the fetch once, on mount, not on every render - Bonus (expected in a complete answer): add an
isLoadingboolean so “still fetching” and “fetched but empty” aren’t both shown as “No data”
Companies: Nike