Introduction Flashcards

1
Q

What is React?

A

A library for creation of “composable” UI components using Javascript and XML.

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

What are the main advantages of React?

A
  1. Reactive Rendering
  2. Composable Components
  3. Abstracted Document model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a React component ?

A

In simpler terms a React component is nothing but the Javascript class, which must have a “render” method which returns the description of “Component’s UI”.
This description will be in JSX format.

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

Write the general syntax of React component?

A
class Hello extends React.Component {
   render () {
       <h1> Hello World </h1>
   }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How React allow us to write “tags” (html/xml”) inside the Javascript code? How browser understands this JSX?

A

React uses JSX (Javascript extension) for writing the UI components. By this way, we can add tags (xml or html) inside the components.
The browser doesn’t understands this JSX, hence we need a trans compiler which transforms the JSX code into Javascript.

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

What’s the shortest way to bootstrap a react application?

A

By using “create-react-app” package.

npm install -g create-react-app

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

What is npx?

A

NPX is the package which gets automatically installed, when we install the npm.T he npx is used to run the “npm packages”.

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

How to use npx to create a react based project?

A

npx create-react-app todo

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

What is the package/directory structure created by the create-react-app?

A

Whenever we create any project using “create-react-app”, it creates the following directory structure:

  1. public directory
  2. src directory
  3. package.json
  4. .gitignore file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the purpose of “public/index.html” file created by the create-create-app utility?

A

“index.html” is the main file loaded in user’s browser, whenever a user hits the application.
It contains the “root” element which will contain the entire application.

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

What’s the purpose of “src/index.js” file created by the create-create-app utility?

A

This is the main “javascript” file, which is responsible for starting the react application in user’s browser.
This file is also responsible for configuring the react application.

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

What’s the purpose of “src/app.js” file created by the create-create-app utility?

A

This is nothing but the react component, which contains the “html” content which will be displayed to the user. It also contains the “javascript” file required for the content.

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

what is main difference between npm and npx?

A

npm is used to install packages.
npx is used to execute packages.
In react based development, npx is only used when we need to create a new “project”, rest all other package management is done by “npm”.

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

How to add “bootstrap” library to you react application?

A
  1. Install bootstrap to your project:
    npm install bootstrap
  2. Import bootstrap css in index.js
    import ‘bootstrap/dist/css/bootstrap.css’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to start the react application?

A

npm start

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

What is the difference between “render” and “return” inside a React Component?

A

Render is the lifecycle function, which is called whenever a component is updated.
Return is used to return the “react element” in JSX format.

17
Q

How a react element is returned by the component?

A

A react element is returned from the “render” method inside the Component class.
It returns the “react element” which is displayed to the user.
e.g. return (

<div> <p> my react element </p> </div>

)

18
Q

What is a “react element”?

A

A react element is nothing but the “html element” which is visible to the user.

19
Q

What’s the main different between import and require?

A

“require” and “modules.export” is CommonJS feature.

“import” and “export” is ES6 feature.

20
Q

How to use import/export, if we are using the CommonJS?

A

We need to use the “transcompiler” like Babel, which transcompiles the code into ES5.

21
Q

Write the general syntax of React component?

A

React component is just a class, which contains the render function.

import React, { Component } from ‘react’;

export default class App extends Component {
  render () {
     return (
          <div class="root"> <p> hello world </p> </div>
   }
}
22
Q

How to provide “class” attribute to HTML element in JSx?

A

It is done by using “className” attribute.

23
Q

What will happen, if we use “plain” HTML attributes in react element instead of JSX attribute?

A

We will get error inside the console with name “Invalid DOM property”.

24
Q

What is an expression inside the react component?

A

The expression is the mechanism, which gets evaluated to a “value” whenever a component is called. It is always written inside “curly braces”.
e.g. { this.state.data }

25
Q

How to initialise the state data inside a constructor and used in an expression?

A

The state data is initialised inside the JS constructor.

26
Q

Wha is the “props” variable used inside the component?

A

A “props” or “properties” is the important variable which is required to configure one component by another.
Whenever a component is called, the data is passed via props variable.

27
Q

Explain the “state” property inside the “react” component?

A

The “state” property is used to define the “state” data.

28
Q

Write general syntax of using “Expression” inside the react component

A
import React, { Component } from 'react';
export default class App extends Component {
  constructor(props){
    super(props);
    this.state = {
         userName = "Nandan"
   }
 }
}
29
Q

How Dynamic content are displayed inside the React component?

A

Dynamic contents are displayed using the “expressions”.

The expressions are using the “state data”.

30
Q

How does React knows, when to update the “react component”?

A

whenever there is a change in the “state of the component i.e. this.state”, the react calls the render method, which re-evaluate the expressions, hence the component gets updated.

31
Q

Is it right to say, the entire dynamism in react component is based on “state” of the components?

A

yes. If we change the state, the react “re-renders” the component.

32
Q

What is done by filter() function of Array in Javascript?

A

The filter function returns the “sub-array” based on the “test call-back function”.

33
Q

What should be returned by the “test callback” function provided to the “filter” function of array?

A

It should return true or false.

If “true” is returned, then it will keep that element in the subarray, otherwise drop it.

34
Q

Explain the functionality of “filter” function of array?

A
  1. It iterate the array for each element.
  2. Get’s the first element and pass same to the “callback” function.
  3. The function gets the element value, and put the logic on the value.
  4. The callback function returns the “true/false” based on the logic applied on “item’s” value.
  5. If the returned value is “true”, the subarray will contain this value otherwise drops same.
35
Q

How can we can count the elements returned by the filter() function?

A

By calling ‘length” variable of returned subArray:

myArray.filter( item => item.first === true ).length

36
Q

What’s the purpose of input element?

A

The Input Element is used to get the text from the user.

37
Q

What are the important attributes of input element?

A
  1. className
  2. value
  3. onChange
38
Q

Should we place a closing tag for input element?

A

No, “input element” is a void element, it should not contain “closing” tag or inner element.

39
Q

What is done by Array’s find function?

A

The find() function returns the first “item” which satisfies the find condition, passed as callback function.