react Flashcards

1
Q

What is React?

A

React is a free and open-source front-end JavaScript library for building user interfaces or 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

Elements are the smallest building blocks of React apps. An element specifies what should be there in our UI. An Element is a plain object describing what we want to appear in terms of the DOM nodes.

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

by using ReactDOM.render(element, container)

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

What is Babel?

A

Babel is a toolchain that translates ES6 code into ES5.

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

What is a Plug-in?

A

Plug-in 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
6
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.

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

By using Babel Loader. (web pack bundles files together and babel is a tool that makes code able to be parsed by most browsers.) Webpack loader will run code through babel before files are bundled into one.

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

What is JSX?

A

JSX is an extension to the JavaScript language syntax which provides a way to structure component rendering using syntax familiar to many developers.

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

Since JSX compiles into calls to React.createElement, the React library must also always be in scope from your JSX code.

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

By using plugin’@babel/plugin-transform-react-jsx’ on webpack.config.js.

first determines the file hierarchy for the project and generates a dependency graph. From the dependency graph it compiles the code to a single source, using Babel to translate and remove the import and export statements, and convert JSX into standard JavaScript.

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

What is a React component?

A

Components let you split the UI into independent, reusable pieces. 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
12
Q

How do you define a function component in React?

A

write JavaScript function and pass in single argument “props” (which is an object) and return react element. function components must start with capital letter.

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

What are props in React?

A

Props are arguments passed into React components.

Props are passed to components via HTML attributes.

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

How do you pass props to a component?

A

Props are also how you pass data from one component to another, as parameters.

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

How do you pass props to a component?

A

We pass them as attributes to components.

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

How do you create “class” component in React?

A

When creating a React component, the component’s name MUST start with an upper case letter. A class component must include the extends React.Component statement. This statement creates an inheritance to React.Component, and gives your component access to React.Component’s functions.The component also requires a render() method, this method returns HTML.

class Car extends React.Component {
  render() {
    return <h2>Hi, I am a Car!</h2>;
  }
}
17
Q

How do you access props in a class component?

A

By using the ‘this’ keyword.

18
Q

How do you access props in a class component?

A

By using the ‘this’ keyword. for example: this.props.text

19
Q

What is the purpose of state in React?

A

State is a plain JavaScript object used by React to represent an information about the component’s current situation. giving us control over the element.

20
Q

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

A

pass in name of function as the event handler

21
Q

What are controlled components?

A

A controlled component is a component that renders form elements and controls them by keeping the form data in the component’s state.

22
Q

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

A

value and onChange (props or attributes)

23
Q

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

A

map

24
Q

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

A

elements inside the map() call need keys

25
Q

What does express.static() return?

A

finds and returns static files requested. (static() returns a function)

26
Q

What is the local __dirname variable in a Node.js module?

A

__dirname is an environment variable that tells you the absolute path of the directory containing the currently executing file.

27
Q

What does the join() method of Node’s path module do?

A

The path. join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

28
Q

What does fetch() return?

A

The fetch() method in JavaScript is used to request to the server and load the information in the webpages. The request can be of any APIs that returns the data of the format JSON or XML. This method returns a promise that resolves to response object.

29
Q

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

A

Without options Fetch will always act as a get request.

30
Q

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

A

pass in config object as second parameter and specify which method will be used in uppercase letters.
fetch(‘https://jsonplaceholder.typicode.com/users’, {
method: ‘POST’
})

31
Q

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

How do you pass data to a child component?

A

In the parent component, create a callback function. This callback function will retrieve the data from the child component. Pass the callback function to the child as a props from the parent component. The child component calls the parent callback function using props and passes the data to the parent component

33
Q

How do you pass data to a child component?

A

We use props. In the parent component, create a callback function. This callback function will retrieve the data from the child component. Pass the callback function to the child as a props from the parent component. The child component calls the parent callback function using props and passes the data to the parent component