LFZ Quiz questions (Senior parts 2) Flashcards

1
Q

(react-elements)

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

(react-elements)

What is a React element?

A

Object

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

(react-elements)

How do you mount a React element to the DOM?

A

ReactDOM.render(element, container[, callback])
Render a React element into the DOM in the supplied container and return a reference to the component (or returns null for stateless components).

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

(babel-intro)

What is Babel?

A

Babel is a JavaScript compiler.
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.

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

(babel-intro)

What is a Plug-in?

A

In computing, a plug-in (or plugin, add-in, add-in, add-on, or addon) is a software component that adds a specific feature to an existing computer program. When a program supports plug-ins, it enables customization.

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

(babel-intro)

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
7
Q

(babel-intro)

How can you make Babel and Webpack work together?

A

within a webpack.config.js file, we can add a rule to use loader for the babel-loader and plugins(ex. babel-loader).
Or we can use inline command or CLI.

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

(react-jsx)

What is JSX?

A

It is a syntax extension to JavaScript used in React. It describes what the UI should look like. JSX produces React “elements”

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

(react-jsx)

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

A

We can use a babel-loader and a plugin of ‘@babel/plugin-transform-react-jsx’.

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

(react-function-components)

What is a React component?

A

Components let you split the UI into independent, reusable pieces, and think about each piece in isolation.
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

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

(react-function-components)

How do you define a function component in React?

A

function keyword, component name and function parameter of property.

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

(react-function-components)

How do you define a function component in React?

A
It is very similar to the function declaration of JavaScript.
function keyword, component name and function parameter as property. Function name should start with a capital letter.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

(react-function-components)

How do you mount a component to the DOM?

A

we can use ReactDOM.render() method with passing in the first parameter as React element.

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

(react-props-and-expressions)

What are props in React?

A

Props in React is arbitrary inputs when components are declared and object.

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

(react-props-and-expressions)

How do you pass props to a component?

A
  1. You can pass any JavaScript expression as a prop, by surrounding it with {}.
  2. You can pass a string literal as a prop.
  3. If you pass no value for a prop, it defaults to true.
  4. If you already have props as an object, and you want to pass it in JSX, you can use … as a “spread” operator to pass the whole props object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(react-props-and-expressions)

How do you write JavaScript expressions in JSX?

A

You can write any JavaScript expression within a curly brace pair.

17
Q

(react-rendering-lists)

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

A

map() method

18
Q

(react-rendering-lists)

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

A

numbered string

19
Q

(react-class-components)

How do you create “class” component in React?

A
  1. Create an ES6 class, with the same name, that extends React.Component.
  2. Add a single empty method to it called render().
  3. Move the body of the function into the render() method.
  4. Replace props with this.props in the render() body.
  5. Delete the remaining empty function declaration.
20
Q
react-class-components
How do you access props in a class component?
A

this.props

21
Q

(react-events-and-state)

What is the purpose of state in React?

A

State is similar to props, but it is private and fully controlled by the component.

22
Q

(react-events-and-state)

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

A

We can add an React event in an HTML element using on+EventName using camelCase and passing function name within {}
ex)

Activate Lasers

23
Q

single responsibility principle

A

that is, a component should ideally only do one thing. If it ends up growing, it should be decomposed into smaller subcomponents.

24
Q

(react-form-controls)

What are controlled components and how do you work with them?

A

a JavaScript function that handles the submission of the form and has access to the data that the user entered into the form. The standard way to achieve this is with a technique called “controlled components”.

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

25
Q

(promises)

What are the three states a Promise can be in?

A
  • pending: initial state, neither fulfilled nor rejected.
  • fulfilled: meaning that the operation completed successfully.
  • rejected: meaning that the operation failed.
26
Q

(promises)

How do you handle the fulfillment of a Promise?

A

if the operation completed successfully, call promise.resolve() method to return a new promise object.
after getting the return, we can use then() method of promise object and call-back function.

27
Q

(promises)

How do you handle the rejection of a Promise?

A

promise. reject() method.

promise. catch(call-back function) or second call-back of then() method.

28
Q

(fetch)

What does fetch() return?

A

A Promise that resolves to a Response object.

https://developer.mozilla.org/en-US/docs/Web/API/Response

29
Q

(fetch)

What is the default request method used by fetch()?

A

GET

30
Q

(fetch)

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

We can use method parameter of fetch() method

The request method, e.g., GET, POST. Note that the Origin header is not set on Fetch requests with a method of HEAD or GET.

31
Q

(fetch-in-react)

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request

32
Q

(fetch-in-react)

Name three React.Component lifecycle methods.

A

constructor(), render(), componentDidMount()

https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/

33
Q

(fetch-in-react)

How do you pass data to a child component?

A

using props property