React Flashcards

1
Q

What is React?

A

A JavaScript library for building user interfaces

A library is a JavaScript file that contains a bunch of functions, and those functions accomplish some useful task for your webpage.

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

What is a React element?

A

An element describes what you want to see on the screen:

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

How do you mount a React element to the DOM?

A

ReactDOM.render(element, container[, callback])

Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements.

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

What is JSX?

A

A syntax extension to JavaScript, it produces react elements and lets you use HTML syntax in JavaScrupt

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

Why must the React object be imported when authoring JSX in a module?

A

The JS will be undefined if you don’t

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

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A
Add this to webpack config file, 
loader: 'babel-loader',
          options: {
            plugins: [
              '@babel/plugin-transform-react-jsx'
            ]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a React component?

A

Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.

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

How do you define a function component in React?

A
function CustomButton([props]) {
  return  Click Me!;
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you mount a component to the DOM?

A

ReactDOM.render(
,
document.querySelector(‘#root’)
);

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

What are props in react

A

objects getting passed to react elements

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

How do you pass props to a component?

A

like arguments

const element = (
  <div>

</div>
);

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

How do you write JavaScript expressions in JSX?

A

close expression in curly braces, they mean stark end of a JavaScript expression

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

How do you create “class” component in React?

A
class CustomButton extends React.Component {
  render() {
    return  {this.props.text};
  }
}

A render method is required

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

How do you access props in a class component?

A

{this.props.text}

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

What is the purpose of state in React?

A

React components has a built-in state object. The state object is where you store property values that belongs to the component. When the state object changes, the component re-renders.

State is like our data model for React, we use it to determine what the user should see when it renders.

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

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

A

With JSX you pass a function as the event handler, rather than a string.

{‘Thanks’};

17
Q

What Array method is commonly used to create a list of React elements?

A

map

18
Q

What is the best value to use as a “key” prop when rendering lists?

A

The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys.

19
Q

What are controlled components?

A

In HTML, form elements such as , , and typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with setState().

We can combine the two by making the React state be the “single source of truth”. Then the React component that renders a form also controls what happens in that form on subsequent user input. An input form element whose value is controlled by React in this way is called a “controlled component”.

A react component that reacts to the changes of an element that it is wrapped around.

It receives it value via state and it has a change handler that updates that state.

20
Q

What two props must you pass to an input for it to be “controlled”?

A

value and onChange

21
Q

When does React call a component’s componentDidMount method?

A

After render, but before page is finished loading

22
Q

Name three React.Component lifecycle methods.

A

constructor, render, componentDidMount

23
Q

How do you pass data to a child component?

A

as a prop to the child component