react-flashcards

(70 cards)

1
Q

What is JSX?

A

A syntax extension for JavaScript that lets you write HTML-like markup inside JS files. It’s stricter than HTML — you must close all tags (e.g. <br></br>) and a component can only return one root element (wrap with <> … </> if needed).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the rule for React component names vs HTML tags?

A

React component names must start with a capital letter (e.g. <MyButton></MyButton>). HTML tags must be lowercase (e.g. <div>). This is how React distinguishes them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you embed JavaScript expressions in JSX?

A

Use curly braces {}. For content: {user.name}. For attributes: src={user.imageUrl}. For inline styles: style={{ color: ‘red’ }} (double curlies = an object inside JSX curlies).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you specify a CSS class in JSX?

A

Use className instead of class: <img></img>. This is because ‘class’ is a reserved word in JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does ‘export default’ do in a component file?

A

It specifies the main component in the file. Other components can be exported with named exports. A file can have one default export but many named exports.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two types of ‘model’ data in React?

A

Props and State. Props are like function arguments — passed from parent to child. State is a component’s memory — it lets a component track info and change it in response to interactions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ‘lifting state up’ mean?

A

Moving state from child components to their closest common parent, then passing it back down as props. This lets sibling components share and stay in sync with the same data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is conditional rendering in React?

A

Using standard JS techniques (if/else, ternary ? :, logical &&) to conditionally include JSX. There’s no special React syntax for conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why do list items need a ‘key’ prop?

A

Keys let React identify which items changed, were added, or removed. They should be unique among siblings (typically a database ID). Never use array index as key if the list can reorder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a React Fragment (<> </>)?

A

An empty wrapper that lets you return multiple JSX elements without adding extra DOM nodes. Equivalent to <React.Fragment>. Use <Fragment key={id}> when you need a key.</React.Fragment>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why must components be pure functions?

A

A pure component only calculates its output — given the same inputs (props, state, context), it always returns the same JSX. It should not mutate pre-existing variables or objects. This lets React optimize rendering, skip redundant work, and enable features like Suspense.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is React’s component tree?

A

A hierarchical structure where the root component renders child components, which render their own children. React uses this tree to determine render order and manage state. State is tied to a component’s position in this tree.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Hooks in React?

A

Functions starting with ‘use’ that let you tap into React features (state, effects, context, etc.) from function components. Built-in hooks include useState, useEffect, useRef, useContext, useReducer, useMemo, useCallback, and more.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the Rules of Hooks?

A

1) Only call hooks at the TOP LEVEL of your component or custom hook — never inside loops, conditions, or nested functions. 2) Only call hooks from React function components or custom hooks. This ensures React can correctly track hook state across renders.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why can’t you call hooks inside conditions or loops?

A

React relies on the ORDER hooks are called to match each hook with its state. If you conditionally skip a hook, every hook after it gets the wrong state. Extract a new component instead if you need conditional hook usage.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does useState return?

A

A pair: [currentValue, setterFunction]. Convention: const [thing, setThing] = useState(initialValue). The setter triggers a re-render with the new value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Does useState merge objects like class setState?

A

No. Unlike class components, the setter REPLACES the entire value. For objects, spread the previous state: setUser({ …user, name: ‘New’ }). Same for arrays — never mutate directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a functional update with useState?

A

Passing a function to the setter: setCount(prev => prev + 1). Use this when the new state depends on the previous state, especially when batching multiple updates. React will pass the latest pending state as ‘prev’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does ‘state as a snapshot’ mean?

A

When you call setState, the current render’s state variable doesn’t change. The new value is available on the NEXT render. Each render has its own snapshot of state, props, and event handlers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What happens if you call setState 3 times with the same value in one handler?

A

React batches state updates. If you do setCount(count + 1) three times, count is the same stale value each time — you only get +1, not +3. Use functional updates: setCount(c => c + 1) three times to get +3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you update objects in state immutably?

A

Create a new object with spread: setUser({ …user, name: ‘New’ }). For nested objects: setUser({ …user, address: { …user.address, city: ‘NYC’ } }). Never mutate state objects directly — React won’t detect the change.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you update arrays in state immutably?

A

Use non-mutating methods: filter() to remove, map() to transform, […arr, newItem] to add, .slice() to copy a portion. Avoid push, pop, splice, reverse, sort directly on state arrays — copy first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is useEffect for?

A

Synchronizing your component with an external system (APIs, browser DOM, timers, subscriptions, etc.). It runs AFTER the component renders and paints to the screen. It’s an ‘escape hatch’ from React’s declarative model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What do the different dependency arrays mean in useEffect?

A

useEffect(fn) — runs after EVERY render. useEffect(fn, []) — runs only after FIRST render (mount). useEffect(fn, [a, b]) — runs after renders where a or b changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the cleanup function in useEffect?
The function you RETURN from your effect. React calls it before re-running the effect (with new deps) and on unmount. Use it to unsubscribe, clear timers, close connections, etc. Setup and cleanup should be 'symmetrical'.
26
Why does useEffect run twice in development (Strict Mode)?
React intentionally mounts, unmounts, and re-mounts your component in dev to help you find missing cleanup functions. If your effect breaks on the second run, you need a cleanup function.
27
How do you handle data fetching with useEffect correctly?
Use a cleanup flag: let ignore = false; fetch().then(result => { if (!ignore) setData(result) }); return () => { ignore = true }. This prevents race conditions when the component re-renders before the fetch completes.
28
When should you NOT use useEffect?
Don't use it for: transforming data for rendering (compute during render instead), handling user events (use event handlers), resetting state when props change (use a key), or anything that can be calculated from existing props/state.
29
What is useLayoutEffect and when should you use it?
Same API as useEffect, but fires synchronously BEFORE the browser repaints. Use it when you need to measure/manipulate the DOM before the user sees it (e.g., tooltips, measurements). Most effects should use useEffect.
30
What does useRef return and how is it different from state?
Returns a mutable object { current: initialValue } that persists across renders. Unlike state: 1) Changing ref.current does NOT trigger a re-render. 2) It's mutable. 3) You can read/write it anytime (except during render for non-initialization).
31
What are the two main use cases for useRef?
1) Holding a reference to a DOM node: then inputRef.current.focus(). 2) Storing mutable values that don't affect rendering (timer IDs, previous values, counters, etc.).
32
When should you use a ref vs state?
Use state when the value affects what's rendered on screen (React needs to know about changes). Use a ref when you need to persist a value across renders but DON'T need React to re-render when it changes.
33
What problem does Context solve?
Prop drilling — when you need to pass data through many layers of components that don't use it themselves. Context lets a parent provide data that any descendant can read directly, regardless of depth.
34
How do you create and use Context (React 19)?
1) const ThemeCtx = createContext('default'). 2) Wrap with provider: . 3) Consume: const theme = useContext(ThemeCtx). Note: In React 19 you use directly instead of .
35
What is the new use() API for Context in React 19?
use(SomeContext) reads context like useContext, but unlike hooks, it can be called conditionally (e.g., after an early return). It can also unwrap promises for Suspense. It's the direction React is heading.
36
When should you use useReducer instead of useState?
When you have complex state logic with multiple sub-values, when the next state depends on the previous one, or when many event handlers modify state in a similar way. Reducers consolidate state update logic in one place.
37
What is the signature of useReducer?
const [state, dispatch] = useReducer(reducerFn, initialState). reducerFn takes (currentState, action) and returns newState. You update state by calling dispatch({ type: 'action_name', ...payload }).
38
What's the benefit of combining useReducer with Context?
It lets any component deep in the tree read state AND dispatch actions without prop drilling. Create two contexts (one for state, one for dispatch), provide both from the parent using the reducer. This is a powerful pattern for scaling state management.
39
What does useMemo do?
Caches the RESULT of a calculation between re-renders. const value = useMemo(() => expensiveCalc(a, b), [a, b]). Only recomputes when dependencies change. Use it for genuinely expensive calculations, not everything.
40
What does useCallback do?
Caches a FUNCTION definition between re-renders. const fn = useCallback(() => { doStuff(a) }, [a]). Equivalent to useMemo(() => fn, deps). Useful when passing callbacks to components wrapped in React.memo.
41
useCallback(fn, deps) is equivalent to what?
useMemo(() => fn, deps). useCallback caches the function itself, useMemo caches any value. useCallback is syntactic sugar for the common case of memoizing functions.
42
When should you NOT use useMemo/useCallback?
Don't prematurely optimize. Most re-renders are fast. Use them only when: 1) A calculation is noticeably slow. 2) Passing values to React.memo-wrapped children. 3) A value is used as a dependency of another hook. Profile first with React DevTools.
43
What is React.memo and how does it relate to useCallback?
React.memo(Component) skips re-rendering a component when its props haven't changed (shallow comparison). But if you pass a new function reference each render, memo can't help. useCallback keeps the reference stable so memo works.
44
What is useDeferredValue?
Defers updating part of the UI to keep the rest responsive. const deferredQuery = useDeferredValue(query). React 19 added an initialValue param. Use it for expensive rendering that shouldn't block user input.
45
What is useTransition?
const [isPending, startTransition] = useTransition(). Marks a state update as non-urgent — React can interrupt it to handle more urgent updates (like typing). In React 19, startTransition supports async functions (Actions).
46
What are Actions in React 19?
Functions that use async transitions (via startTransition, useActionState, or form actions). They automatically manage: pending states, optimistic updates, error handling, and form resets. Convention: functions using async transitions are called 'Actions'.
47
What is useActionState?
const [state, submitAction, isPending] = useActionState(async (prevState, formData) => { ... }, initialState). Wraps an async function to track its result and pending state. Replaces manual useState for pending/error tracking.
48
What is useOptimistic?
const [optimisticVal, setOptimistic] = useOptimistic(currentVal). Shows an optimistic UI while an async action is in progress. Automatically reverts to currentVal when the action completes or errors.
49
What is the use() API?
A new React 19 API for reading resources in render. use(promise) suspends until the promise resolves (works with Suspense). use(context) reads context (can be called conditionally, unlike useContext). Only call in render, but CAN be called conditionally.
50
How do form Actions work in React 19?
— pass a function to the action prop. React automatically calls it with FormData on submit, manages pending state, and resets the form for uncontrolled components.
51
What is useFormStatus?
import { useFormStatus } from 'react-dom'. Returns { pending, data, method, action } for the nearest parent . Use it in submit buttons or form UI to show loading states without prop drilling.
52
How do refs work differently in React 19?
ref is now a regular prop on function components — no more forwardRef needed! Also, ref callbacks can return a cleanup function (like effects). React 19 will deprecate forwardRef and the old null-calling pattern.
53
What changed about Context providers in React 19?
You can render directly instead of . Cleaner syntax. will be deprecated in a future version.
54
What is the React Compiler?
An official build-time tool (v1.0 released Oct 2025) that automatically adds memoization (useMemo/useCallback equivalent) to your components. It eliminates much of the need to manually optimize with these hooks.
55
What are React Server Components (RSC)?
Components that render on the server (at build time or per-request), not in the browser. They can directly access databases, file systems, etc. Their code is never sent to the client, reducing bundle size.
56
What is the 'use server' directive?
Marks a function as a Server Action — an async function that executes on the server but can be called from Client Components. It does NOT mark Server Components (there is no directive for those).
57
What is the 'use client' directive?
Marks a file as a Client Component boundary. Everything in that file and its imports runs on the client. Without this directive, components are Server Components by default (in frameworks that support RSC).
58
What is the event naming convention in React?
Props that represent events: onSomething (e.g., onClick, onSubmit, onHover). Handler functions: handleSomething (e.g., handleClick, handleSubmit). This convention makes data flow clear.
59
Why is immutability important in React?
React detects changes by reference comparison. If you mutate an object/array, the reference stays the same and React won't know to re-render. Immutable updates (spread/copy) create new references that React can detect.
60
What is a Custom Hook?
A function starting with 'use' that composes built-in hooks. It lets you extract and reuse stateful logic across components. Each component calling the hook gets its own independent copy of that state.
61
What are the 5 steps of 'Thinking in React'?
1) Break UI into a component hierarchy. 2) Build a static version (no state). 3) Find the minimal state representation. 4) Identify where state should live. 5) Add inverse data flow (callbacks from children to parents).
62
How should you choose your state structure?
Principles: 1) Group related state. 2) Avoid contradictory state. 3) Avoid redundant/derived state (compute it instead). 4) Avoid duplication. 5) Avoid deeply nested state (flatten it). Keep state minimal.
63
What are Error Boundaries?
Class components (or libraries like react-error-boundary) that catch JavaScript errors in their child component tree, log them, and display a fallback UI. They don't catch errors in event handlers, async code, or SSR.
64
What is Suspense?
}>. It shows a fallback UI while child components are loading (lazy-loaded components, data fetching with use(), etc.). It lets you declaratively specify loading states.
65
What is the difference between controlled and uncontrolled components?
Controlled: React state drives the value (value={state} + onChange). You have full control. Uncontrolled: the DOM manages its own state (use defaultValue + refs to read). Controlled is preferred in most cases.
66
How do you reset a component's state?
Change its 'key' prop. When the key changes, React destroys the old instance and creates a new one with fresh state. E.g., resets when selectedId changes.
67
What does React's one-way data flow mean?
Data flows DOWN the component tree via props. Children communicate UP to parents via callback functions passed as props. This makes data flow predictable and easier to debug.
68
What are resource preloading APIs in React 19?
prefetchDNS(), preconnect(), preload(), preinit() — from 'react-dom'. They tell the browser to load resources early (fonts, scripts, stylesheets), improving page performance. They deduplicate automatically.
69
How does React 19 handle document metadata?
You can render , <meta>, and <link> tags inside any component. React automatically hoists them to <head>. Works with SSR and streaming. For advanced use cases, consider a metadata library. </div> </div> </div> <div class='flashcard-row thin-card is-blurrable' data-a-button-url='/sign-up?cardId=680776459&deckId=21518373&packId=23733969&returnTo=%2Fpacks%2F23733969%2Fsubscribe&source=ugc-cards&subject=0+React+By+Marf' data-card-is-blurrable data-number='70' id='card-680776459'> <div class='header'> 70 </div> <div class='card-face question'> <div class='question-content'> How does React 19 handle stylesheets? </div> </div> <div class='card-face answer'> <div class='answer-content'> Add precedence prop to <link rel="stylesheet">. React manages insertion order, ensures stylesheets load before revealing dependent content, and deduplicates across components. </div> </div> </div> </div> </div> </div> <div class='flashcards-sidebar'> <div class='sidebar-content'> <div class='sidebar-header'> <div class='pack-heading'> <a class="pack-icon-link" href="/packs/0-react-by-marf-23733969"><img class="pack-icon" src="/pks/images/icons/ugc-blue-bg-20ed217093b36d8842ca.svg" /> </a><div class='pack-labels'> <a class="pack-name" href="/packs/0-react-by-marf-23733969">0 React By Marf</a> <div class='pack-suffix'>flashcards</div> </div> </div> <div class='deck-list-headings'> <div class='decks-heading'>Decks in class (9)</div> <div class='card-count-heading'># Cards</div> </div> </div> <ul class='deck-list-items'> <a class='deck-link selected' href='/flashcards/react-flashcards-21518373/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>react-flashcards</div> <div class='deck-card-count'>70</div> </li> </a> <a class='deck-link ' href='/flashcards/thinking-in-react-21518393/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>Thinking In React</div> <div class='deck-card-count'>18</div> </li> </a> <a class='deck-link ' href='/flashcards/react-dev-tools-21642781/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>react dev tools</div> <div class='deck-card-count'>46</div> </li> </a> <a class='deck-link ' href='/flashcards/react-tic-tac-toe-21652721/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>react tic tac toe</div> <div class='deck-card-count'>34</div> </li> </a> <a class='deck-link ' href='/flashcards/quick-start-21652728/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>quick start</div> <div class='deck-card-count'>23</div> </li> </a> <a class='deck-link ' href='/flashcards/rendering-21652882/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>rendering</div> <div class='deck-card-count'>20</div> </li> </a> <a class='deck-link ' href='/flashcards/performance-21652892/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>performance</div> <div class='deck-card-count'>21</div> </li> </a> <a class='deck-link ' href='/flashcards/mental-model-21652911/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>mental model</div> <div class='deck-card-count'>22</div> </li> </a> <a class='deck-link ' href='/flashcards/you-might-not-need-an-effect-21653824/packs/23733969'> <li class='deck-list-item'> <div class='deck-name'>you might not need an effect</div> <div class='deck-card-count'>23</div> </li> </a> </ul> </div> </div> <div id='tooltip-controller'></div> <div data='{"packId":23733969,"source":"spaced-repetition-modal","subject":"0 React By Marf","resources":{"deckId":21518373,"packId":23733969},"returnTo":"/packs/23733969/subscribe"}' id='spaced-repetition-modal'></div> <div id='banner-controller'></div> <div id='dialog-modal-controller'></div> </div> <div class='band band-footer'> <div class='footer-main'> <ul class='sections'> <li class='section key-links'> <p class='section-heading'> Key Links </p> <ul class='options-list'> <li class='option'> <a id="footer-pricing-link" class="option-link" href="/pricing?paywall=upgrade">Pricing</a> </li> <li class='option'> <a class="option-link" href="/companies">Corporate Training</a> </li> <li class='option'> <a class="option-link" href="/teachers">Teachers & Schools</a> </li> <li class='option'> <a class="option-link" target="_blank" rel="nofollow noopener noreferrer" href="https://itunes.apple.com/us/app/brainscape-smart-flashcards/id442415567?mt=8">iOS App</a> </li> <li class='option'> <a class="option-link" target="_blank" rel="nofollow noopener noreferrer" href="https://play.google.com/store/apps/details?id=com.brainscape.mobile.portal">Android App</a> </li> <li class='option'> <a class="option-link" target="_blank" rel="noopener" href="https://www.brainscape.com/faq">Help Center</a> </li> </ul> </li> <li class='section subjects'> <p class='section-heading'> Subjects </p> <ul class='options-list'> <li class='option'> <a class="option-link" href="/subjects/medical-nursing">Medical & Nursing</a> </li> <li class='option'> <a class="option-link" href="/subjects/law">Law Education</a> </li> <li class='option'> <a class="option-link" href="/subjects/foreign-languages">Foreign Languages</a> </li> <li class='option'> <a class="option-link" href="/subjects-directory/a">All Subjects A-Z</a> </li> <li class='option certified-classes'> <a class="option-link" href="/learn">All Certified Classes</a> </li> </ul> </li> <li class='section company'> <p class='section-heading'> Company </p> <ul class='options-list'> <li class='option'> <a class="option-link" href="/about">About Us</a> </li> <li class='option'> <a target="_blank" class="option-link" rel="nofollow noopener noreferrer" href="https://brainscape.zendesk.com/hc/en-us/articles/115002370011-Can-I-earn-money-from-my-flashcards-">Earn Money!</a> </li> <li class='option'> <a target="_blank" class="option-link" href="https://www.brainscape.com/academy/">Academy</a> </li> <li class='option'> <a target="_blank" class="option-link" href="https://brainscapeshop.myspreadshop.com/all">Swag Shop</a> </li> <li class='option'> <a target="_blank" rel="nofollow noopener" class="option-link" href="/contact">Contact</a> </li> <li class='option'> <a class="option-link" href="/terms">Terms</a> </li> <li class='option'> <a class="option-link" href="/privacy-policy">Privacy Policy</a> </li> <li class='option'> <a target="_blank" class="option-link" href="https://www.brainscape.com/academy/brainscape-podcasts/">Podcasts</a> </li> <li class='option'> <a target="_blank" class="option-link" href="/careers">Careers</a> </li> </ul> </li> <li class='section find-us'> <p class='section-heading'> Find Us </p> <ul class='social-media-list'> <li class='option twitter-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://twitter.com/Brainscape"><img data-src="/pks/images/logos/twitterx-af917e8b474ed7c95a19.svg" alt="twitter badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> <li class='option linkedin-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://www.linkedin.com/company/brainscape/"><img data-src="/pks/images/logos/linkedin-2f15819658f768056cef.svg" alt="linkedin badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> <li class='option facebook-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://www.facebook.com/Brainscape"><img data-src="/pks/images/logos/facebook-1598a44227eabc411188.svg" alt="facebook badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> <li class='option youtube-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://www.youtube.com/c/BrainscapeNY"><img data-src="/pks/images/logos/youtube-7f2994b2dc1891582524.svg" alt="youtube badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> <li class='option pinterest-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://www.pinterest.com/brainscape/"><img data-src="/pks/images/logos/pinterest-04f51aa292161075437b.svg" alt="pinterest badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> <li class='option tiktok-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://www.tiktok.com/@brainscapeu"><img data-src="/pks/images/logos/tiktok-644cf4608bd73fbbb24f.svg" alt="tiktok badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> <li class='option insta-badge group'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://www.instagram.com/brainscape/"><img data-src="/pks/images/logos/insta-210cc2d059ae807961d2.svg" alt="insta badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="24" height="24" /></a> </li> </ul> <div class='get-the-app'> <div class='qr-code'> <img data-src="/pks/images/qr-codes/get-app-from-footer-qr-566425384a51031bd6d9.png" alt="QR code" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="130" height="130" /> </div> <div class='app-badges'> <div class='badge apple-badge'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://apps.apple.com/us/app/brainscape-smart-flashcards/id442415567"><img data-src="/pks/images/badges/apple-badge-b6e4f380fb879821d601.svg" alt="apple badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="124" height="50" /></a> </div> <div class='badge android-badge'> <a rel="nofollow noopener noreferrer" target="_blank" class="option-link" href="https://play.google.com/store/apps/details?id=com.brainscape.mobile.portal&utm_source=global_co&utm_medium=prtnr&utm_content=Mar2515&utm_campaign=PartBadge&pcampaignid=MKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1"><img data-src="/pks/images/badges/android-badge-a2251833dc7f6ca8879c.svg" alt="android badge" class="lazy-load" src="/pks/images/general/placeholder-2f8e0834f3c4456dc1cc.jpg" width="124" height="50" /></a> </div> </div> </div> </li> </ul> </div> <div class='footer-blurb'> Brainscape helps you reach your goals faster, through stronger study habits. <br> © 2026 Bold Learning Solutions. <a class="option-link" href="/terms">Terms and Conditions</a> </div> </div> <div class='modals'></div> <script> if (typeof window.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'object') { __REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function() {}; } </script> <script> window.addEventListener('load', () => { setTimeout(() => { const script = document.createElement('script'); script.src = "/pks/js/public/content/flashcards-page-f6c2701456e414bbe1cd.js"; script.defer = true; document.body.appendChild(script); }, 0); }); </script> <script> document.addEventListener("mainSharedready", () => { GaHelper.setGaDimension("dimension1","No"); }); </script> <script type='application/ld+json'> {"@context":"https://schema.org/","@type":"Quiz","about":{"@type":"Thing","name":"react-flashcards"},"hasPart":[{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is JSX?","acceptedAnswer":{"@type":"Answer","text":"A syntax extension for JavaScript that lets you write HTML-like markup inside JS files. It's stricter than HTML — you must close all tags (e.g. ) and a component can only return one root element (wrap with \u003c\u003e ... \u003e if needed)."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What's the rule for React component names vs HTML tags?","acceptedAnswer":{"@type":"Answer","text":"React component names must start with a capital letter (e.g. ). HTML tags must be lowercase (e.g. ). This is how React distinguishes them."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"How do you embed JavaScript expressions in JSX?","acceptedAnswer":{"@type":"Answer","text":"Use curly braces {}. For content: {user.name}. For attributes: src={user.imageUrl}. For inline styles: style={{ color: 'red' }} (double curlies = an object inside JSX curlies)."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"How do you specify a CSS class in JSX?","acceptedAnswer":{"@type":"Answer","text":"Use className instead of class: . This is because 'class' is a reserved word in JavaScript."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What does 'export default' do in a component file?","acceptedAnswer":{"@type":"Answer","text":"It specifies the main component in the file. Other components can be exported with named exports. A file can have one default export but many named exports."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What are the two types of 'model' data in React?","acceptedAnswer":{"@type":"Answer","text":"Props and State. Props are like function arguments — passed from parent to child. State is a component's memory — it lets a component track info and change it in response to interactions."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What does 'lifting state up' mean?","acceptedAnswer":{"@type":"Answer","text":"Moving state from child components to their closest common parent, then passing it back down as props. This lets sibling components share and stay in sync with the same data."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is conditional rendering in React?","acceptedAnswer":{"@type":"Answer","text":"Using standard JS techniques (if/else, ternary ? :, logical \u0026\u0026) to conditionally include JSX. There's no special React syntax for conditions."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"Why do list items need a 'key' prop?","acceptedAnswer":{"@type":"Answer","text":"Keys let React identify which items changed, were added, or removed. They should be unique among siblings (typically a database ID). Never use array index as key if the list can reorder."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is a React Fragment (\u003c\u003e \u003e)?","acceptedAnswer":{"@type":"Answer","text":"An empty wrapper that lets you return multiple JSX elements without adding extra DOM nodes. Equivalent to . Use when you need a key."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"Why must components be pure functions?","acceptedAnswer":{"@type":"Answer","text":"A pure component only calculates its output — given the same inputs (props, state, context), it always returns the same JSX. It should not mutate pre-existing variables or objects. This lets React optimize rendering, skip redundant work, and enable features like Suspense."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is React's component tree?","acceptedAnswer":{"@type":"Answer","text":"A hierarchical structure where the root component renders child components, which render their own children. React uses this tree to determine render order and manage state. State is tied to a component's position in this tree."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What are Hooks in React?","acceptedAnswer":{"@type":"Answer","text":"Functions starting with 'use' that let you tap into React features (state, effects, context, etc.) from function components. Built-in hooks include useState, useEffect, useRef, useContext, useReducer, useMemo, useCallback, and more."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What are the Rules of Hooks?","acceptedAnswer":{"@type":"Answer","text":"1) Only call hooks at the TOP LEVEL of your component or custom hook — never inside loops, conditions, or nested functions. 2) Only call hooks from React function components or custom hooks. This ensures React can correctly track hook state across renders."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"Why can't you call hooks inside conditions or loops?","acceptedAnswer":{"@type":"Answer","text":"React relies on the ORDER hooks are called to match each hook with its state. If you conditionally skip a hook, every hook after it gets the wrong state. Extract a new component instead if you need conditional hook usage."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What does useState return?","acceptedAnswer":{"@type":"Answer","text":"A pair: [currentValue, setterFunction]. Convention: const [thing, setThing] = useState(initialValue). The setter triggers a re-render with the new value."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"Does useState merge objects like class setState?","acceptedAnswer":{"@type":"Answer","text":"No. Unlike class components, the setter REPLACES the entire value. For objects, spread the previous state: setUser({ ...user, name: 'New' }). Same for arrays — never mutate directly."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is a functional update with useState?","acceptedAnswer":{"@type":"Answer","text":"Passing a function to the setter: setCount(prev =\u003e prev + 1). Use this when the new state depends on the previous state, especially when batching multiple updates. React will pass the latest pending state as 'prev'."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What does 'state as a snapshot' mean?","acceptedAnswer":{"@type":"Answer","text":"When you call setState, the current render's state variable doesn't change. The new value is available on the NEXT render. Each render has its own snapshot of state, props, and event handlers."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What happens if you call setState 3 times with the same value in one handler?","acceptedAnswer":{"@type":"Answer","text":"React batches state updates. If you do setCount(count + 1) three times, count is the same stale value each time — you only get +1, not +3. Use functional updates: setCount(c =\u003e c + 1) three times to get +3."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"How do you update objects in state immutably?","acceptedAnswer":{"@type":"Answer","text":"Create a new object with spread: setUser({ ...user, name: 'New' }). For nested objects: setUser({ ...user, address: { ...user.address, city: 'NYC' } }). Never mutate state objects directly — React won't detect the change."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"How do you update arrays in state immutably?","acceptedAnswer":{"@type":"Answer","text":"Use non-mutating methods: filter() to remove, map() to transform, [...arr, newItem] to add, .slice() to copy a portion. Avoid push, pop, splice, reverse, sort directly on state arrays — copy first."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is useEffect for?","acceptedAnswer":{"@type":"Answer","text":"Synchronizing your component with an external system (APIs, browser DOM, timers, subscriptions, etc.). It runs AFTER the component renders and paints to the screen. It's an 'escape hatch' from React's declarative model."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What do the different dependency arrays mean in useEffect?","acceptedAnswer":{"@type":"Answer","text":"useEffect(fn) — runs after EVERY render. useEffect(fn, []) — runs only after FIRST render (mount). useEffect(fn, [a, b]) — runs after renders where a or b changed."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"What is the cleanup function in useEffect?","acceptedAnswer":{"@type":"Answer","text":"The function you RETURN from your effect. React calls it before re-running the effect (with new deps) and on unmount. Use it to unsubscribe, clear timers, close connections, etc. Setup and cleanup should be 'symmetrical'."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"Why does useEffect run twice in development (Strict Mode)?","acceptedAnswer":{"@type":"Answer","text":"React intentionally mounts, unmounts, and re-mounts your component in dev to help you find missing cleanup functions. If your effect breaks on the second run, you need a cleanup function."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"How do you handle data fetching with useEffect correctly?","acceptedAnswer":{"@type":"Answer","text":"Use a cleanup flag: let ignore = false; fetch().then(result =\u003e { if (!ignore) setData(result) }); return () =\u003e { ignore = true }. This prevents race conditions when the component re-renders before the fetch completes."}},{"@context":"https://schema.org/","@type":"Question","eduQuestionType":"Flashcard","text":"When should you NOT use useEffect?","acceptedAnswer":{"@type":"Answer","text":"Don't use it for: transforming data for rendering (compute during render instead), handling user events (use event handlers), resetting state when props change (use a key), or anything that can be calculated from existing props/state."}}],"educationalAlignment":[{"@type":"AlignmentObject","alignmentType":"educationalSubject","targetName":"react-flashcards"}]} </script> <script type='application/ld+json'> {"@context":"https://schema.org","@type":"Organization","name":"Brainscape","url":"https://www.brainscape.com/","logo":"https://api.brainscape.com/core/images/shared/brainscape-logo.svg","sameAs":["https://www.facebook.com/Brainscape","https://x.com/brainscape","https://www.linkedin.com/company/brainscape","https://www.instagram.com/brainscape/","https://www.tiktok.com/@brainscapeu","https://www.pinterest.com/brainscape/","https://www.youtube.com/@BrainscapeNY"],"contactPoint":{"@type":"ContactPoint","telephone":"(929) 334-4005","contactType":"customer service","availableLanguage":["English"]},"founder":{"@type":"Person","name":"Andrew Cohen"},"description":"Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.","address":{"@type":"PostalAddress","streetAddress":"159 W 25th St, Ste 517","addressLocality":"New York","addressRegion":"NY","postalCode":"10001","addressCountry":"USA"}} </script> </body> </html>