React Flashcards
(150 cards)
What is React?
A JavaScript library for building user interfaces.
Who created React?
Facebook.
What is JSX?
JavaScript XML – a syntax extension that lets you write HTML in JS.
What is a component in React?
A reusable piece of UI.
What are the two types of components?
Functional and Class components.
What is a functional component?
A function that returns JSX.
How do you define a functional component?
function MyComponent() { return <div />; }
What is a hook?
A function that lets you use state or lifecycle in functional components.
What does useState
do?
Adds state to functional components.
What does useEffect
do?
Runs side-effects like data fetching or subscriptions.
What are props?
Inputs passed to components.
How are props passed?
As attributes on JSX elements.
What is state?
Data that changes over time and triggers re-render.
How do you lift state up?
Move it to a common ancestor and pass it down via props.
Can props be modified?
No, props are read-only.
What is the second argument of useEffect
?
A dependency array.
When does useEffect
run?
After every render unless dependencies restrict it.
How to run useEffect
only once?
Pass an empty dependency array: []
.
How to clean up in useEffect
?
Return a cleanup function inside useEffect
.
What is a common use case for useEffect
?
Fetching data from an API.
How do you conditionally render in React?
Using if
, ternary (? :
), or logical AND (&&
).
What is the shorthand for conditional rendering?
{condition && <Component />}
Can you use switch-case inside JSX?
Usually outside JSX, then return appropriate component.
What is the benefit of keys in a list?
Helps React identify which items changed.