DEV Community

Md. Hasibul Hasan
Md. Hasibul Hasan

Posted on

Basic React Concepts

  1. What are reactjs? Tell us about the advantages and disadvantages of using react js. Answer: React is a very popular open-source JavaScript front-end library, that is used to build a user interface based on UI components. The advantages of React.js are given below, i) It has reusable components and code. ii) It is easy to learn and easy to use. iii) It helps to create a dynamic web application and it’s quite easier. iv) React has a dedicated tool that’s why it is easy to debug. v) React has a Unidirectional data flow. vi) It is also known to be SEO friendly. vii) It offers a very rich JavaScript library.

The disadvantage of React.js is given below,
i) it has a high pace of development.
ii) the documentation of react is poor.
iii) it has only the UI layers view part.
iv) web development community considers jsx as a barrier.

  1. Difference between useEffect and useState?
    Answer: We know both useState and useEffect enhance functional components to make them do things that classes can but functional components (without hooks) cannot. The difference between useEffect and useState is given below,
    useState basically used to add state variables in the functional components. useState function is straight forward it allows you to add state accessors inside the functional component. But on the other side useEffect function hook are allows you to use the group of lifecycle methods like, componentDidMount(), componentDidUpdate(), componentWillUnmount(). So this lifecycle method you can use in useEffect function hook in your functional component.

  2. What is the component lifecycle of React?
    Answer: In React every Component has a lifecycle of its own, component lifecycle can be defined as a series of methods that are called in different stages of the component’s existence.
    You can monitor or manipulate this lifecycle during three phases. The definition is pretty good but what are different stages? A React Component can go through four stages of its lifecycle. These four stages are given below,
    Initialization: This is the first stage of react component. In this stage, the component is constructed with the given Props and state. This stage is completed in the constructor of a Component Class.
    Mounting: Mounting is the second stage Where rendering the JSX is returned by the render method itself. There are four built-in methods in this Mounting phase. Like constructor(), getDerivedStateFromProps(), render(),componentDidMount(). In this following methods render method is required and it will always be called.
    Updating: The next stage is Updating, in this stage, the state of a component is updated, and also the application is repainted.
    Unmounting: The final stage is Unmounting. Unmounting stage is the last step of the component lifecycle where the component is removed from the page.
    React.js provides the developers a set of predefined functions that are very useful and you can call this function around specific events in the lifecycle of the component. Developers have mostly overridden the functions with their desired logic to execute accordingly.

Top comments (0)