React Flashcards

1
Q

What is React?

A

a FrameWork and not just a library.
framework = kind of library, define bunch of functions, but never call it. framework is in charge of when to call the function.
library.
open-source front-end “JavaScript library for building user interfaces” based on UI components.

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

What is a React element?

A

A React Element is what gets returned from components. A plain object describing what you want to appear on the screen in terms of the DOM nodes or other components

an Object, with custom properties on it. has $$typeof, key, props:{children}, ref, type, owner. react element is NOT a DOM element. it only describe the DOM element. real DOM elements are more complex than react elements (which is more simpler)

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

createElement, and querySelect the ROOT real element, and mount the DOM to render() method.

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

What is JSX?

A

JavaScript XML, a syntax extension to JavaScript. allows us to write HTML in React, easier to write and add HTML in React, creates an element to be used in JS
JS syntax extension to write JS. JavaScript plus.

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

Because it’s used in the final code of babel outputs (babel calls React.createElement in its output so ‘createElement’ would not work without the ‘React’ object)

babel converts it to javascript, the react object needs to be there to convert to React.createElement.

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

to have a rule for all files with jsx, will load with “babel-loader”, within the webpack.config.js

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

What is a React component?

A

Components (function or class) let you split the UI into independent, reusable pieces, and think about each piece in isolation.
Conceptually, components are like JavaScript functions.

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

// name of the component needs to be CAPITALIZED since babel will translate
function ComponentName() {
return react element (type) = has to return react element
}

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

get the container, and use the root and render.
root.render(< ComponentName />)

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

What are props in React?

A

Object.
properties, being used for passing data from one component to another. HTML attributes.

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

pass as key, value pair that looks like HTML attribute.
text=”I” text=”know” text=”React!” color=”red

in the function

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

by surrounding the expressions in a curly braces
wrap it in curly braces

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 ComponentName extends React.Component {
render() {
return “reactElement” {this.props.”propertyKey”}
“reactElement”
}
}

{ JS expression syntax }

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

by using this.props.”propertyKey”

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

built-in React that is used to contain data or information about the component. A component’s state can change over time; whenever it changes, the component re-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

”<”ReactElementofType prop”eventHandler?”={ this.Method } “>”

17
Q

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

A

map() method. takes a callback function.

18
Q

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

A

unique identifier. key NEEDS to be unique from it’s siblings.

19
Q

What are controlled components?

A

Controlled components in React are those in which form data is handled by the component’s state. Component that get the changed value from the callback function. When input value is changed,we can use onChange function in Controlled Component and also we can get the value using DOM like ref.

value and onChange is saved somewhere in the state.

20
Q

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

A

value prop, what it’s current input is and onChange prop, to know when it’s changed, run the function