DEV Community

Hassan Zahar Rifat
Hassan Zahar Rifat

Posted on

You Must Know the Answers to the 7 Most Basic Questions about React

1. What is reactjs? Tell us about advantages and disadvantages of using react js.

-> React.js is a JavaScript library that is used to build scalable Frontend UI.

Advantages:
Easy to learn.

Gives syntactic sugar by which HTML code can be written inside JavaScript.
By writing one component once, it can be used whenever it needs to be used.
Huge community support

Disadvantages:

Core React.js frameworks is not SEO friendly
Huge dependency on many third party libraries.

2. What is JSX? How does it work?
-> JSX refers to JavaScript XML. It gives syntactic sugar and ease to React.js. By using JSX, we can write HTML code inside JavaScript without the burden of using createElement(), appendChild() or template literals.

3. What is Virtual dom? What are the differences between virtual and real dom?
Or what is the diff algorithm? How does it work?
-> Virtual DOM is a virtual copy of real DOM. It is kept in memory and is synced with real DOM by ReactDOM. DOM manipulation is a less speedy and less efficient process and this is why without rendering the whole document for a little change changing the particular portion is efficient. Virtual DOM does this very well. Whenever change happens, virtual DOM captures the change using diff algorithm and then it updates just that important part that needs to be updated.

4. Differences between props and state?
-> Props are immutable and can be passed as child components but states are mutable, owned by the component and mutable.

5. What is the purpose of useState? When and why will you use it?
-> The useState hook is used for initializing, storing and managing the states of any variable. -> const [state, setState] = useState();

6. What is prop drilling?
-> Sometimes it becomes necessary to pass a value to a child component and from that child component to it’s child component as props. This process of nested passing is called prop drilling.

7. why do we need to inject dependency for useEffect?
-> Using useEffect, it’s necessary to inject dependencies as whenever the state of the dependencies change, the code inside the useEffect executes.

Top comments (0)