10 things you need to know about react

  1. Virtual DOM : DOM stands for document object model .DOM is a representation of the html element of your webpage .Virtual DOM is virtual representation of real DOM. When state of component changes ,the virtual DOM updated and compare the present version with previous one to figure out what actually has been changed .This is call diffing ..After that the parent tree re-render to give the updated UI. Then it updated to real DOM .Virtual DOM faster and efficient than real DOM . Real DOM slow a bit.

State is a JavaScript object that stores component’s dynamic data and it enables a component to keep track of changes between renders.

or

  • The state is a built-in React object that is used to contain data or information about the component. The state in a component can change over time, and whenever it changes, the component re-renders.

12.What is react Hook ?

These are in-built functions that allow developers to use state and lifecycle methods within components in React.

OR

Hooks are a new feature added in React v16.8. It allows to use all React features without writing class components. For example, before version 16.8, we need a class component to manage state of a component. Now we can keep state in a functional component using useState hook.

13. Features of react ?

  • JSX

14.Why can’t browsers read JSX?

Browsers can only read JavaScript objects but JSX in not a regular JavaScript object. Thus to enable a browser to read JSX, first, we need to transform JSX file into a JavaScript object using JSX transformers like Babel and then pass it to the browser.

15. Can I skip an effect on updates? If you want the useEffect to run only on updates except initial mount, you can make use of useRef to keep track of initialMount with useEffect without the second parameter

16.Why do we need a Router in React? A Router is used to define multiple routes and when a user types a specific URL, if this URL matches the path of any ‘route’ defined inside the router, then the user is redirected to that particular route. So basically, we need to add a Router library to our app that allows creating multiple routes with each leading to us a unique view.

17.Why we use JSX?

  • It is faster than regular JavaScript because it performs optimization while translating the code to JavaScript.

18.Props vs State?

state:Hold information of components,Child components cannot access,changeable.

States vs Props

ConditionsStateProps1. Receive initial value from parent componentYesYes2. Parent component can change valueNoYes3. Set default values inside componentYesYes4. Changes inside componentYesNo5. Set initial value for child componentsYesYes6. Changes inside child componentsNoYes

19. Differentiate between Real DOM and Virtual DOM.

Real DOM vs Virtual DOM

Real DOM Virtual DOM1. It updates slow. 1. It updates faster.

2. Can directly update HTML. 2. Can’t directly update HTML.

3. Creates a new DOM if element updates.3. Updates the JSX if element updates.

4. DOM manipulation is very expensive.4. DOM manipulation is very easy.

5. Too much of memory wastage.5. No memory wastage.

20.DefaultProps :is a property in React component used to set default values for the props argument. It will be changed if the prop property is passed. Here props is property .So defaultProps is default property ,means it set the default value for props argument. It can be changed if the prop property is passed. So simple right . Props used to data from one component to another component.

21.What is react ?

React is a front-end JavaScript library focused on building a user interface with components.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store