react Flashcards

1
Q

What is React?

A

a JavaScript library for building user interfaces

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

What is a React element?

A

It’s an object that virtually describes the DOM nodes that a component represents

has key, props (children), ref, type(h1, div, etc), _owner
React element is a plain JS object that describes what the DOM obj should look like (NOT a DOM element)
framework stores in memory, not what we see?

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
query DOM for real DOM element
createRoot using the DOM element
mount the createElement to DOM from root with render()

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

What is Babel?

A

toolchain used to convert JS versions (can convert code into older JS version syntax for browsers that might not support JS versions that are newer)

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

What is a Plug-in?

A

software component that adds a specific feature to an existing computer program.

adds more functionality or customization to a program
software already works w/o plug-in; plug-in is an add on
if some code of software modifies a larger piece of code/software that would’ve worked just fine w/o it, its a plugin

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

What is a Webpack loader?

A

transformations that are applied to the source code of a module. They allow you to pre-process files as you import or “load” them.

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

How can you make Babel and Webpack work together?

A

install bable core (babel)
install webpack
install babel-loader (connects the two above)
specify which babel plugins to use!!

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

What is JSX?

A

a syntax extension to JavaScript
JSX produces React “elements”

syntax extension used to write react elements
*extension: addon to JS

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

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

A

b/c JSX is used to create React elements so you need react to do that

needs to be there so when JSX is converted to React.createElement, react is there

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

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

A

install bable/core, webpack, babel-loader
install @babel/plugin-transform-react-jsx plugin

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

user defined component

A

a function or a class

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

What is a React component?

A

basically a function or a class
independent and reusable bits of code. They serve the same purpose as JavaScript functions, but work in isolation and return HTML.
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
13
Q

How do you define a function component in React?

A

accepts a single “props” (which stands for properties) object argument with data and returns a React element
like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

function functionnamethatstartswithacapitalletter (optional props parameter) {
return a React element;
}

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

How do you mount a component to the DOM?

A

root.render()
create a react element w/ component name to put in render!!
**ex: root.render()
**don’t call function in render()

React is a framework, we define functions, classes, etc. but we don’t call functions in frameworks!!!

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

What are props in React?

A

an object!

looks like html attributes
kind of like parameters in JS functions?

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

How do you pass props to a component?

A

looks like html attributes

specify when writing react elements in a react component (as key value pairs)

17
Q

How do you write JavaScript expressions in JSX?

A

have to write EXPRESSIONS in curly braces!

*no statements: if/else, loop, etc.

18
Q

curly braces in jsx

A

means JS expression

19
Q

How do you create “class” component in React?

A

class Componentname extends React.Component {
render( ) {
return react element;
}
}

*need render() for methods!!!
*if using constructor function, need to include super(props)!!!!!

20
Q

How do you access props in a class component?

A

“this”
props

21
Q

es6 super(_

A
22
Q

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

A

array.map()

23
Q

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

A

a string that uniquely identifies a list item among its siblings.
most often you would use IDs if available

24
Q

What are controlled components?

A

An input form element whose value is controlled by React

value of contolled component is stored in component state

25
Q

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

A

value and onChange function

26
Q

What is the purpose of state in React?

A

keep track of values that change over time

state can change over time

data model for a component

27
Q

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

A

pass event handler as a prop of that react element

ex: onClick={this.handleClick}