Responding to events Flashcards

1
Q

How can you handle events in a React component?

A

By passing a function as a prop to an element like <button>.</button>

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

What is the correct way to pass an event handler to an element?

A

onClick={handleClick}, not onClick={handleClick()}.

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

Where are event handler functions defined in a React component?

A

Inside a component.

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

What can event handler functions access?

A

Props.

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

How can you pass an event handler from a parent to a child component?

A

Declare an event handler in a parent and pass it as a prop to a child.

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

Can you define your own event handler props?

A

Yes, with application-specific names.

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

What happens to events in terms of propagation?

A

Events propagate upwards.

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

How can you prevent event propagation?

A

Call e.stopPropagation() on the first argument.

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

What should you call to prevent unwanted default browser behavior for events?

A

Call e.preventDefault().

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

What is a good alternative to propagation for calling an event handler?

A

Explicitly calling an event handler prop from a child handler.

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