React.js Flashcards

1
Q

What is a React component?

A

independent and reusable bits of code.

They serve the same purpose as JavaScript functions, but work in isolation and return HTML via a render() function.

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

How do you define a function component in React?

A
function functionName(props) {
  return (
    jsx;
  );
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you mount a component to the DOM?

A

ReactDOM.render(element, container)
element is a component ex)
container is usually a div with root

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

What are props in React?

A

“Props” is a special keyword in React, which stands for properties and is being used for passing data from one component to another.

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

How do you pass props to a component?

A

Use it as a parameter in the function component

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

How do you write JavaScript expressions in JSX?

A

In curly braces

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

How do you create “class” component in React?

A
class componentName extends React.component {
  render() {
    return { this.props.text };
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you access props in a class component?

A

this.props

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

What is the purpose of state in React?

A

To update state and change UI (re-render) accordingly

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

How do you pass an event handler to a React element?

A

{ this.state.isClicked ? ‘Thanks!’ : ‘Click Me!’}

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