React Flashcards

1
Q

What is Webpack?

A

Webpack is a tool that lets you compile JavaScript modules, also known as module bundler

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

How do you add a devDependency to a package?

A

npm install –save-dev name or npm i -D webpack webpackcli

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

What is an NPM script?

A

An npm script is a convenient way to bundle common shell commands for your project.

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

How do you execute Webpack with npm run?

A

npm run build

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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
6
Q

What is a React element?

A

A React Element is what gets returned from components. It’s an object that virtually describes the DOM nodes that a component represents. is an object that describes the dom element.

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

How do you mount a React element to the DOM?

A

root.render(element)

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

What is Babel?

A

Babel is a JavaScript compiler converts es6 to es5.

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

What is a Plug-in?

A

a plug-in (or plugin, add-in, addin, add-on, or addon) is a software component that adds a specific feature to an existing computer program.

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

What is a Webpack loader?

A

Loaders are transformations that are applied to the source code of a module. They allow you to pre-process files as you import or “load” them. Thus, loaders are kind of like “tasks” in other build tools and provide a powerful way to handle front-end build steps. Loaders can transform files from a different language (like TypeScript) to JavaScript or load inline images as data URLs. Loaders even allow you to do things like import CSS files directly from your JavaScript modules!

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

How can you make Babel and Webpack work together?

A

If Babel is a translator for JS, you can think of Webpack as a mega-multi-translator that works with all kinds of languages (or assets). For example, Webpack often runs Babel as one of its jobs.

with babel-loader through webpack.config.js and add the plug ins

babel core + webpack + babel loader + tell babel which plugs ins to use.

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

What is JSX?

A

a react extension Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, …children) function.

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

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

A

you are using react.createlement method when authoring jsx.

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

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

A

using the babel loader and the plugn in

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

What is a React component?

A

Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen. this is useful so you can reuse it.

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

How do you define a function component in React?

A

class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}

17
Q

How do you mount a component to the DOM?

A

const root = ReactDOM.createRoot(document.getElementById(‘root’));
const element = ;
root.render(element);

18
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.

19
Q

How do you pass props to a component?

A

You can pass any JavaScript expression as a prop, by surrounding it with {}. For example, in this JSX:

20
Q

How do you write JavaScript expressions in JSX?

A

{ }

21
Q

What are props in React?

A

props is an object. if the react elements have prop values they will be key value pairs in the object.

22
Q

How do you pass props to a component?

A

it looks like an html attribute, as key value pairs in your react element.

23
Q

How do you write JavaScript expressions in JSX?

A

You can pass any JavaScript expression as a prop, by surrounding it with {}. For example, in this JSX:

24
Q

How do you create “class” component in React?

A

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

25
Q

How do you access props in a class component?

A

this.props.text etc

26
Q

what is the purpose of state in react

A

the purpose of state is to keep track of values that change over time.

27
Q

how do you pass an event handler to a react element

A

the prop with an assignment operator and curl braces with the this.method

28
Q

if you do not see the call site of this you can not be sure of the value of this
// bind guarantees the value of this when the function or method is called
// bind returns a copy of a function with a permanent this.
referring to the bind in the constructor
undefined instead of window in es6 methods

A
29
Q

react order
1.react deletes everything from the container dom element and owns it thereafter.
2. react looks at your react element and decides what to do.
-if the react element is an html type button, div , h1 -> dom creation
-if the react element is a function component type(call it and use the elements)
-if the react element is a class component type -> new ( and call render)
// third option - class
// immediately calls the render method of the new object

{
type:”button”,
props: {
onclick;fn,
children; “click me!”
}
}
react does dom creation make the real dom match the above object and also adds the event listener for click
when our click listener runs, it calls setstate
this starts a transition from the current state to the next state.
by replacing the old properties in this state
a re-render is scheduled with the new state
react receives a new react element from the render method

{
type: button,
props: {
children: thanks!
}
}

A
30
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:

31
Q

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

A

map method

32
Q

What are controlled components?

A

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”.

value is kept in a component state, listen for changes and update the state

33
Q

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

A

value and onChange