Interview Questions & Answers

react-js

  • The ‘switch’ keyword is used when you want to display only a single route to be rendered amongst the several defined routes.
  • The <switch> tag when in use matches the typed URL with the defined routes in sequential order.

Conventional Routing

  • Pages Involved – Each view corresponds to a new file.
  • URL Changes – A HTTP request is sent to server and corresponding HTML page is received.
  • Feel – User actually navigates across different pages for each view.

React Router

  • Pages Involved – Only single HTML page is involved.
  • URL Changes – Only the History attribute is changed.
  • Feel – User is duped thinking he is navigating across different pages.

  • API is “All about components”.
  • Can be visualized as single root component.
  • No need to manually set History value.
  • Separate packages for Web and Native platforms.

  • Helps in defining multiple routes inside the Router with each route leading to a unique view.

The ‘switch’ keyword is used to when you want to display only a single route to be rendered amongst the several defined routes.

<switch>
    <route exact path=’/’ component={Home}/>,
    <route path=’/posts/:id’ component={NewPost}/>,
    <route path=’/posts’ component={Post}/>
</switch>

  • Powerful routing library
  • Helps in adding new screens and flows to the application
  • Keeps the URL in sync with data that’s being displayed on the web page
  • Has simple API

  • Redux – Thunk is a middleware that lets call action creators that return a function instead of an action object.
  • The thunk can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met.
  • Basically, it sits between action creator and reducer in the React-Redux flow.

  1. Predictability
  2. Maintainability
  3. Sever side rendering
  4. Developers tool
  5. Huge community
  6. Ease of testing
  7. Precise organization of code