General question Flashcards

1
Q

A === B

A

a and b are equal in both value and type

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

A == B

A

a and b are equal in value alone

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

What is closure

A

Closure is the combination of a function bundled together (enclosed) with references to its surrounding state(the lexical environment). In Javascript , closures are created every time a function is created, at function creation time.

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

What is a promise

A

A promise is an object that may produce a single value sometime in the future. Either resolved or unresolved

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

This KEYWORD

A

refers to the object it belongs to. It’s set with bind()

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

What is SASS

A

its a css preprocessor. Gives you room to access variables and functions. You can nest and let more. It compiles the code.

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

403

A

UNAUTHORIZED REQUEST

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

404

A

NOT FOUND

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

201

A

RESOURCE RECREATED

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

400

A

CLIENT ERROR/BAD REQUEST

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

500

A

SERVER ERROR

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

What is the difference between the Virtual DOM and the real DOM

A

Diffing….the virtual dom looks at the state and the next state of the dom and say oh this is what I am to change..

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

Shadow DOM

A

Its a browser specific technology.

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

JSX

A

1) in full, it’s called Javascript Xml
2) write javascript with an html-like template syntax(not HTML, not a string)
3) produces elements that represent objects

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

What is the difference between an element and a component?

A

A component is a function that returns an element.
Element is created by jsx as an object.

You can create react without jsx.
Like react.createElement(‘div’,,null,’hello’)

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

How to pass a value from a child to parent?

A

Functional props. The parent will pass functional props to child then the child will call the function then pass it to the parent.

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

What is the difference between props and state?

A

Props is passed through a component.

State is manage in a given component. If you need it in another component, you will have to pass it as props.

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

What is a component lifecycle

A

1) mounting - componentdidmount
2) updating - componentdidupdate
3) unmounting - componentwillunmount

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

How do you update the lifecycle in function components?

A

UseEffect

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

What is React?

A

React is an open-source frontend JavaScript library which is used for building user interfaces especially for single page applications. It is used for handling view layer for web and mobile apps. React was created by Jordan Walke, a software engineer working for Facebook. React was first deployed on Facebook’s News Feed in 2011 and on Instagram in 2012.

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

What are the major features of React?

A

The major features of React are:

It uses VirtualDOM instead of RealDOM considering that RealDOM manipulations are expensive.
Supports server-side rendering.
Follows Unidirectional data flow or data binding.
Uses reusable/composable UI components to develop the view.

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

What is JSX?

A

JSX is a XML-like syntax extension to ECMAScript (the acronym stands for JavaScript XML). Basically it just provides syntactic sugar for the React.createElement() function, giving us expressiveness of JavaScript along with HTML like template syntax.

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

What is the difference between Element and Component?

A

An Element is a plain object describing what you want to appear on the screen in terms of the DOM nodes or other components. Elements can contain other Elements in their props. Creating a React element is cheap. Once an element is created, it is never mutated.

The object representation of React Element would be as follows:

const element = React.createElement(
  'div',
  {id: 'login-btn'},
  'Login'
)

The above React.createElement() function returns an object:

{
  type: 'div',
  props: {
    children: 'Login',
    id: 'login-btn'
  }
}

And finally it renders to the DOM using ReactDOM.render():

<div>Login</div>

Whereas a component can be declared in several different ways. It can be a class with a render() method. Alternatively, in simple cases, it can be defined as a function. In either case, it takes props as an input, and returns a JSX tree as the output:

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

How to create components in React?

A

There are two possible ways to create a component.

Function Components: This is the simplest way to create a component. Those are pure JavaScript functions that accept props object as first parameter and return React elements:
function Greeting({ message }) {
  return <h1>{`Hello, ${message}`}</h1>

}

Class Components: You can also use ES6 class to define a component. The above function component can be written as:
class Greeting extends React.Component {
  render() {
    return <h1>{`Hello, ${this.props.message}`}</h1>
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

When to use a Class Component over a Function Component?

A

If the component needs state or lifecycle methods then use class component otherwise use function component. However, from React 16.8 with the addition of Hooks, you could use state , lifecycle methods and other features that were only available in class component right in your function component.

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

What are Pure Components?

A

React.PureComponent is exactly the same as React.Component except that it handles the shouldComponentUpdate() method for you. When props or state changes, PureComponent will do a shallow comparison on both props and state. Component on the other hand won’t compare current props and state to next out of the box. Thus, the component will re-render by default whenever shouldComponentUpdate is called.

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

What is state in React?

A

State of a component is an object that holds some information that may change over the lifetime of the component. We should always try to make our state as simple as possible and minimize the number of stateful components.

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

What are props in React?

A

Props are inputs to components. They are single values or objects containing a set of values that are passed to components on creation using a naming convention similar to HTML-tag attributes. They are data passed down from a parent component to a child component.

The primary purpose of props in React is to provide following component functionality:

Pass custom data to your component.
Trigger state changes.
Use via this.props.reactProp inside component’s render() method.

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

What is the difference between state and props?

A

Both props and state are plain JavaScript objects. While both of them hold information that influences the output of render, they are different in their functionality with respect to component. Props get passed to the component similar to function parameters whereas state is managed within the component similar to variables declared within a function.

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

Why should we not update the state directly?

A

If you try to update state directly then it won’t re-render the component.Instead use setState() method. It schedules an update to a component’s state object. When state changes, the component responds by re-rendering.

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

What is the purpose of callback function as an argument of setState()?

A

The callback function is invoked when setState finished and the component gets rendered. Since setState() is asynchronous the callback function is used for any post action.

Note: It is recommended to use lifecycle method rather than this callback function.

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

What is the difference between HTML and React event handling?

A
  1. In HTML, the event name usually represents in lowercase as a convention:

Whereas in React it follows camelCase convention:

  1. In HTML, you can return false to prevent default behavior:

<a></a>
Whereas in React you must call preventDefault() explicitly:

function handleClick(event) {
  event.preventDefault()
  console.log('The link was clicked.')
}
3. In HTML, you need to invoke the function by appending () Whereas in react you should not append () with the function name. (refer "activateLasers" function in the first point for example)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

How to bind methods or event handlers in JSX callbacks?

A

There are 3 possible ways to achieve this:

Binding in Constructor: In JavaScript classes, the methods are not bound by default. The same thing applies for React event handlers defined as class methods. Normally we bind them in constructor.

class Component extends React.Component {
  constructor(props) {
    super(props)
    this.handleClick = this.handleClick.bind(this)
  }
  handleClick() {
    // ...
  }
}

Public class fields syntax: If you don’t like to use bind approach then public class fields syntax can be used to correctly bind callbacks.

handleClick = () => {
console.log(‘this is:’, this)
}

{‘Click me’}

Arrow functions in callbacks: You can use arrow functions directly in the callbacks.

this.handleClick(event)}>
{‘Click me’}

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

What are synthetic events in React?

A

SyntheticEvent is a cross-browser wrapper around the browser’s native event. It’s API is same as the browser’s native event, including stopPropagation() and preventDefault(), except the events work identically across all browsers.

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

What are inline conditional expressions?

A

You can use either if statements or ternary expressions which are available from JS to conditionally render expressions. Apart from these approaches, you can also embed any expressions in JSX by wrapping them in curly braces and then followed by JS logical operator &&.

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

What is “key” prop and what is the benefit of using it in arrays of elements?

A

A key is a special string attribute you should include when creating arrays of elements. Key prop helps React identify which items have changed, are added, or are removed.

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

What is the use of refs?

A

The ref is used to return a reference to the element. They should be avoided in most cases, however, they can be useful when you need a direct access to the DOM element or an instance of a component.

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

How to create refs?

A

React.createRef(). useRef hook

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

What are forward refs?

A

Ref forwarding is a feature that lets some components take a ref they receive, and pass it further down to a child. React.forwardRef

40
Q

Which is preferred option with in callback refs and findDOMNode()?

A

It is preferred to use callback refs over findDOMNode() API. Because findDOMNode() prevents certain improvements in React in the future.

41
Q

What is Virtual DOM?

A

The Virtual DOM (VDOM) is an in-memory representation of Real DOM. The representation of a UI is kept in memory and synced with the “real” DOM. It’s a step that happens between the render function being called and the displaying of elements on the screen. This entire process is called reconciliation.

42
Q

What is the difference between Shadow DOM and Virtual DOM?

A

The Shadow DOM is a browser technology designed primarily for scoping variables and CSS in web components. The Virtual DOM is a concept implemented by libraries in JavaScript on top of browser APIs.

43
Q

What is React Fiber?

A

Fiber is the new reconciliation engine or reimplementation of core algorithm in React v16. The goal of React Fiber is to increase its suitability for areas like animation, layout, gestures, ability to pause, abort, or reuse work and assign priority to different types of updates; and new concurrency primitives.

44
Q

What is the main goal of React Fiber?

A

The goal of React Fiber is to increase its suitability for areas like animation, layout, and gestures. Its headline feature is incremental rendering: the ability to split rendering work into chunks and spread it out over multiple frames.

Ability to split interruptible work in chunks.
Ability to prioritize, rebase and reuse work in progress.
Ability to yield back and forth between parents and children to support layout in React.
Ability to return multiple elements from render().
Better support for error boundaries.

45
Q

What are controlled components?

A

A component that controls the input elements within the forms on subsequent user input is called Controlled Component, i.e, every state mutation will have an associated handler function.

46
Q

What are uncontrolled components?

A

The Uncontrolled Components are the ones that store their own state internally, and you query the DOM using a ref to find its current value when you need it. This is a bit more like traditional HTML.

47
Q

What is the difference between createElement and cloneElement?

A

JSX elements will be transpiled to React.createElement() functions to create React elements which are going to be used for the object representation of UI. Whereas cloneElement is used to clone an element and pass it new props.

48
Q

What is Lifting State Up in React?

A

When several components need to share the same changing data then it is recommended to lift the shared state up to their closest common ancestor. That means if two child components share the same data from its parent, then move the state to parent instead of maintaining local state in both of the child components.

49
Q

What are the different phases of component lifecycle?

A

The component lifecycle has three distinct lifecycle phases:
initialization

Mounting: The component is ready to mount in the browser DOM. This phase covers initialization from constructor(), getDerivedStateFromProps(), render(), and componentDidMount() lifecycle methods.

Updating: In this phase, the component get updated in two ways, sending the new props and updating the state either from setState() or forceUpdate(). This phase covers getDerivedStateFromProps(), shouldComponentUpdate(), render(), getSnapshotBeforeUpdate() and componentDidUpdate() lifecycle methods.

Unmounting: In this last phase, the component is not needed and get unmounted from the browser DOM. This phase includes componentWillUnmount() lifecycle method.

It’s worth mentioning that React internally has a concept of phases when applying changes to the DOM. They are separated as follows

Render The component will render without any side-effects. This applies for Pure components and in this phase, React can pause, abort, or restart the render.

Pre-commit Before the component actually applies the changes to the DOM, there is a moment that allows React to read from the DOM through the getSnapshotBeforeUpdate().

Commit React works with the DOM and executes the final lifecycles respectively componentDidMount() for mounting, componentDidUpdate() for updating, and componentWillUnmount() for unmounting.

50
Q

What are the lifecycle methods of React?

A

componentWillMount: Executed before rendering and is used for App level configuration in your root component.
componentDidMount: Executed after first rendering and here all AJAX requests, DOM or state updates, and set up event listeners should occur.
componentWillReceiveProps: Executed when particular prop updates to trigger state transitions.
shouldComponentUpdate: Determines if the component will be updated or not. By default it returns true. If you are sure that the component doesn’t need to render after state or props are updated, you can return false value. It is a great place to improve performance as it allows you to prevent a re-render if component receives new prop.
componentWillUpdate: Executed before re-rendering the component when there are props & state changes confirmed by shouldComponentUpdate() which returns true.
componentDidUpdate: Mostly it is used to update the DOM in response to prop or state changes.
componentWillUnmount: It will be used to cancel any outgoing network requests, or remove all event listeners associated with the component.
React 16.3+

getDerivedStateFromProps: Invoked right before calling render() and is invoked on every render. This exists for rare use cases where you need derived state. Worth reading if you need derived state.
componentDidMount: Executed after first rendering and where all AJAX requests, DOM or state updates, and set up event listeners should occur.
shouldComponentUpdate: Determines if the component will be updated or not. By default it returns true. If you are sure that the component doesn’t need to render after state or props are updated, you can return false value. It is a great place to improve performance as it allows you to prevent a re-render if component receives new prop.
getSnapshotBeforeUpdate: Executed right before rendered output is committed to the DOM. Any value returned by this will be passed into componentDidUpdate(). This is useful to capture information from the DOM i.e. scroll position.
componentDidUpdate: Mostly it is used to update the DOM in response to prop or state changes. This will not fire if shouldComponentUpdate() returns false.
componentWillUnmount It will be used to cancel any outgoing network requests, or remove all event listeners associated with the component.

51
Q

What are Higher-Order Components?

A

A higher-order component (HOC) is a function that takes a component and returns a new component. Basically, it’s a pattern that is derived from React’s compositional nature.

We call them pure components because they can accept any dynamically provided child component but they won’t modify or copy any behavior from their input components.

HOC can be used for many use cases:

Code reuse, logic and bootstrap abstraction.
Render hijacking.
State abstraction and manipulation.
Props manipulation.

52
Q

How to create props proxy for HOC component?

A

You can add/edit props passed to the component using props proxy pattern like this:

function HOC(WrappedComponent) {
  return class Test extends Component {
    render() {
      const newProps = {
        title: 'New Header',
        footer: false,
        showFeatureX: false,
        showFeatureY: true
      }
  return 
}   } }
53
Q

What is context?

A

Context provides a way to pass data through the component tree without having to pass props down manually at every level.

For example, authenticated user, locale preference, UI theme need to be accessed in the application by many components.

const {Provider, Consumer} = React.createContext(defaultValue)

54
Q

What is children prop?

A

Children is a prop (this.props.children) that allow you to pass components as data to other components, just like any other prop you use. Component tree put between component’s opening and closing tag will be passed to that component as children prop.

There are a number of methods available in the React API to work with this prop. These include React.Children.map, React.Children.forEach, React.Children.count, React.Children.only, React.Children.toArray.

A simple usage of children prop looks as below,

const MyDiv = React.createClass({
  render: function() {
    return <div>{this.props.children}</div>
  }
})

ReactDOM.render(

    <span>{'Hello'}</span>
    <span>{'World'}</span>
  ,
  node
)
55
Q

How to write comments in React?

A

The comments in React/JSX are similar to JavaScript Multiline comments but are wrapped in curly braces.

56
Q

What is the purpose of using super constructor with props argument?

A

A child class constructor cannot make use of this reference until super() method has been called. The same applies for ES6 sub-classes as well. The main reason of passing props parameter to super() call is to access this.props in your child constructors.

Passing props:

class MyComponent extends React.Component {
  constructor(props) {
    super(props)
console.log(this.props) // prints { name: 'John', age: 42 }   } } Not passing props:
class MyComponent extends React.Component {
  constructor(props) {
    super()
console.log(this.props) // prints undefined
    // but props parameter is still available
    console.log(props) // prints { name: 'John', age: 42 }
  }
  render() {
    // no difference outside constructor
    console.log(this.props) // prints { name: 'John', age: 42 }
  }
}
The above code snippets reveals that this.props is different only within the constructor. It would be the same outside the constructor.
57
Q

What is reconciliation?

A

When a component’s props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with the previously rendered one. When they are not equal, React will update the DOM. This process is called reconciliation.

58
Q

Is lazy function supports named exports?

A

No, currently React.lazy function supports default exports only. If you would like to import modules which are named exports, you can create an intermediate module that reexports it as the default. It also ensures that tree shaking keeps working and don’t pull unused components. Let’s take a component file which exports multiple named components,

59
Q

Why React uses className over class attribute?

A

class is a keyword in JavaScript, and JSX is an extension of JavaScript. That’s the principal reason why React uses className instead of class. Pass a string as the className prop.

60
Q

What are fragments?

A

It’s common pattern in React which is used for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.

61
Q

Why fragments are better than container divs?

A

Below are the list of reasons,

Fragments are a bit faster and use less memory by not creating an extra DOM node. This only has a real benefit on very large and deep trees.
Some CSS mechanisms like Flexbox and CSS Grid have a special parent-child relationships, and adding divs in the middle makes it hard to keep the desired layout.
The DOM Inspector is less cluttered.

62
Q

What are portals in React?

A

Portal is a recommended way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.

ReactDOM.createPortal(child, container)
The first argument is any render-able React child, such as an element, string, or fragment. The second argument is a DOM element.

63
Q

What are stateless components?

A

If the behaviour is independent of its state then it can be a stateless component.

64
Q

What are stateful components?

A

If the behaviour of a component is dependent on the state of the component then it can be termed as stateful component. These stateful components are always class components and have a state that gets initialized in the constructor.

65
Q

How to apply validation on props in React?

A

When the application is running in development mode, React will automatically check all props that we set on components to make sure they have correct type. If the type is incorrect, React will generate warning messages in the console. It’s disabled in production mode due to performance impact. The mandatory props are defined with isRequired.

66
Q

What are the advantages of React?

A

Below are the list of main advantages of React,

Increases the application’s performance with Virtual DOM.
JSX makes code easy to read and write.
It renders both on client and server side (SSR).
Easy to integrate with frameworks (Angular, Backbone) since it is only a view library.
Easy to write unit and integration tests with tools such as Jest.

67
Q

What are the limitations of React?

A

Apart from the advantages, there are few limitations of React too,

React is just a view library, not a full framework.
There is a learning curve for beginners who are new to web development.
Integrating React into a traditional MVC framework requires some additional configuration.
The code complexity increases with inline templating and JSX.
Too many smaller components leading to over engineering or boilerplate.

68
Q

What are error boundaries in React v16?

A

Error boundaries are components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed.

A class component becomes an error boundary if it defines a new lifecycle method called componentDidCatch(error, info) or static getDerivedStateFromError() :

69
Q

What are the recommended ways for static type checking?

A

Normally we use PropTypes library (React.PropTypes moved to a prop-types package since React v15.5) for type checking in the React applications. For large code bases, it is recommended to use static type checkers such as Flow or TypeScript, that perform type checking at compile time and provide auto-completion features.

70
Q

What is the use of react-dom package?

A

The react-dom package provides DOM-specific methods that can be used at the top level of your app. Most of the components are not required to use this module. Some of the methods of this package are:

render()
hydrate()
unmountComponentAtNode()
findDOMNode()
createPortal()
71
Q

What is the purpose of render method of react-dom?

A

This method is used to render a React element into the DOM in the supplied container and return a reference to the component. If the React element was previously rendered into container, it will perform an update on it and only mutate the DOM as necessary to reflect the latest changes.

72
Q

What is ReactDOMServer?

A

The ReactDOMServer object enables you to render components to static markup (typically used on node server). This object is mainly used for server-side rendering (SSR). The following methods can be used in both the server and browser environments:

renderToString()
renderToStaticMarkup()

73
Q

How to use innerHTML in React?

A

The dangerouslySetInnerHTML attribute is React’s replacement for using innerHTML in the browser DOM. Just like innerHTML, it is risky to use this attribute considering cross-site scripting (XSS) attacks. You just need to pass a __html object as key and HTML text as value.

In this example MyComponent uses dangerouslySetInnerHTML attribute for setting HTML markup:

function createMarkup() {
  return { \_\_html: 'First · Second' }
}
function MyComponent() {
  return <div></div>
}
74
Q

How events are different in React?

A

Handling events in React elements has some syntactic differences:

React event handlers are named using camelCase, rather than lowercase.
With JSX you pass a function as the event handler, rather than a string.

75
Q

What will happen if you use setState() in constructor?

A

When you use setState(), then apart from assigning to the object state React also re-renders the component and all its children. You would get error like this: Can only update a mounted or mounting component. So we need to use this.state to initialize variables inside constructor.

76
Q

What is the impact of indexes as keys?

A

Keys should be stable, predictable, and unique so that React can keep track of elements.

77
Q

What will happen if you use props in initial state?

A

If the props on the component are changed without the component being refreshed, the new prop value will never be displayed because the constructor function will never update the current state of the component. The initialization of state from props only runs when the component is first created.

78
Q

How do you conditionally render components?

A

ternary operator. or &&

79
Q

How you use decorators in React?

A

You can decorate your class components, which is the same as passing the component into a function. Decorators are flexible and readable way of modifying component functionality.

80
Q

How do you memoize a component?

A

There are memoize libraries available which can be used on function components.

For example, moize library can memoize the component in another component.

81
Q

What is the lifecycle methods order in mounting?

A

The lifecycle methods are called in the following order when an instance of a component is being created and inserted into the DOM.

constructor()
static getDerivedStateFromProps()
render()
componentDidMount()

82
Q

What is the purpose of getDerivedStateFromProps() lifecycle method?

A

The new static getDerivedStateFromProps() lifecycle method is invoked after a component is instantiated as well as before it is re-rendered. It can return an object to update state, or null to indicate that the new props do not require any state updates.
This lifecycle method along with componentDidUpdate() covers all the use cases of componentWillReceiveProps().

83
Q

What is the purpose of getSnapshotBeforeUpdate() lifecycle method?

A
The new getSnapshotBeforeUpdate() lifecycle method is called right before DOM updates. The return value from this method will be passed as the third parameter to componentDidUpdate().
This lifecycle method along with componentDidUpdate() covers all the use cases of componentWillUpdate().
84
Q

Do Hooks replace render props and higher order components?

A

Both render props and higher-order components render only a single child but in most of the cases Hooks are a simpler way to serve this by reducing nesting in your tree.

85
Q

What is the recommended way for naming components?

A

It is recommended to name the component by reference instead of using displayName.

86
Q

What is the recommended ordering of methods in component class?

A

Recommended ordering of methods from mounting to render stage:

static methods
constructor()
getChildContext()
componentWillMount()
componentDidMount()
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
componentDidUpdate()
componentWillUnmount()
click handlers or event handlers like onClickSubmit() or onChangeDescription()
getter methods for render like getSelectReason() or getFooterContent()
optional render methods like renderNavigation() or renderProfilePicture()
render()
87
Q

What is strict mode in React?

A

React.StrictMode is a useful component for highlighting potential problems in an application. Just like , does not render any extra DOM elements. It activates additional checks and warnings for its descendants. These checks apply for development mode only.

import React from ‘react’

function ExampleApplication() {
  return (
    <div>
    <div>

    </div>

</div>   ) }
88
Q

What is the difference between React and ReactDOM?

A

The react package contains React.createElement(), React.Component, React.Children, and other helpers related to elements and component classes. You can think of these as the isomorphic or universal helpers that you need to build components. The react-dom package contains ReactDOM.render(), and in react-dom/server we have server-side rendering support with ReactDOMServer.renderToString() and ReactDOMServer.renderToStaticMarkup().

89
Q

How to combine multiple inline style objects?

A

You can use spread operator in regular React:

90
Q

What is the recommended approach of removing an array element in React state?

A

The better approach is to use Array.prototype.filter() method.

91
Q

What is React Router?

A

React Router is a powerful routing library built on top of React that helps you add new screens and flows to your application incredibly quickly, all while keeping the URL in sync with what’s being displayed on the page.

92
Q

What is the purpose of push() and replace() methods of history?

A

A history instance has two methods for navigation purpose.

push()
replace()
If you think of the history as an array of visited locations, push() will add a new location to the array and replace() will replace the current location in the array with the new one.

93
Q

What is the difference between React context and React Redux?

A

You can use Context in your application directly and is going to be great for passing down data to deeply nested components which what it was designed for.

Whereas Redux is much more powerful and provides a large number of features that the Context API doesn’t provide. Also, React Redux uses context internally but it doesn’t expose this fact in the public API.

94
Q

How to make AJAX request in Redux?

A

You can use redux-thunk middleware which allows you to define async actions.

95
Q

What is the purpose of the constants in Redux?

A

Constants allows you to easily find all usages of that specific functionality across the project when you use an IDE. It also prevents you from introducing silly bugs caused by typos – in which case, you will get a ReferenceError immediately.

96
Q

how to access the info from the store

A

useSelector hook