quick start Flashcards

(23 cards)

1
Q

What is a React component?

A

A piece of the UI with its own logic and appearance. It’s a JavaScript function that returns markup (JSX).

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

How do you nest one component inside another?

A

Use it as a JSX tag: <MyButton></MyButton>. Component names must start with a capital letter; HTML tags are lowercase.

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

What do the export default keywords do?

A

They specify the main component in the file. export makes it accessible to other files, default marks it as the primary export.

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

What is JSX?

A

A markup syntax that combines JavaScript and HTML-like tags. It’s stricter than HTML — you must close all tags and return a single root element.

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

Why can’t a component return multiple adjacent JSX tags?

A

JSX requires a single root element. Wrap siblings in a <div> or a Fragment (<>…</>) to fix this.

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

How do you specify a CSS class in React?

A

Use the className attribute instead of class: <img></img>. Then define the CSS rules in a separate file.

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

How do you display a JavaScript variable inside JSX?

A

Use curly braces: {user.name}. Curly braces let you “escape into JavaScript” from JSX.

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

How do you use JavaScript expressions in JSX attributes?

A

Use curly braces instead of quotes: src={user.imageUrl}. Quotes pass a literal string, braces evaluate the expression.

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

What does style={{}} mean in JSX?

A

It’s a regular JS object {} inside the JSX curly braces style={ }. The outer braces are JSX syntax, the inner braces are the object literal.

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

How do you do conditional rendering with an if statement?

A

Assign JSX to a variable inside an if/else block, then embed that variable in your returned JSX with curly braces.

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

How do you do inline conditional rendering in JSX?

A

Use the ternary operator: {isLoggedIn ? <Admin></Admin> : <Login></Login>}. For no else branch, use logical &&: {isLoggedIn && <Admin></Admin>}.

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

How do you render a list of items in React?

A

Use array .map() to transform data into JSX elements. Each element needs a unique key prop (usually from your data, like a database ID).

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

Why does React need a key prop on list items?

A

Keys let React track which items changed, were added, or removed. Without them, React can’t efficiently update the list when it changes.

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

How do you respond to a click event?

A

Declare a handler function inside your component, then pass it (don’t call it) to onClick: <button onClick={handleClick}>. No parentheses after the function name.

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

Why should you NOT write onClick={handleClick()} with parentheses?

A

Parentheses call the function immediately during render instead of on click. You need to pass the function reference, not invoke it.

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

What is useState and what does it return?

A

A built-in React Hook that adds state to a component. It returns a pair: the current state value and a setter function, e.g. const [count, setCount] = useState(0).

17
Q

What happens when you call a state setter like setCount(count + 1)?

A

React re-renders the component with the new state value. On the next render, count reflects the updated value.

18
Q

If you render the same component twice, do they share state?

A

No. Each instance of a component gets its own independent state. Clicking one button doesn’t affect the other.

19
Q

What are Hooks in React?

A

Functions starting with use (like useState). They can only be called at the top level of components or other Hooks — not inside conditions or loops.

20
Q

What does “lifting state up” mean?

A

Moving state from child components into their closest common parent so multiple children can share and stay in sync with the same data.

21
Q

How do you share state between two sibling components?

A

Move the state into their common parent. The parent passes the state value and an updater function down to each child as props.

22
Q

What are props?

A

Information passed down from a parent component to a child component via JSX attributes. The child receives them as a function parameter, often destructured: function MyButton({ count, onClick }).

23
Q

Describe the full flow when a button with lifted state is clicked.

A

Child’s onClick fires → calls parent’s handler (passed as prop) → parent calls setState → React re-renders parent → new state value flows down as props to all children.