DEV Community

Cover image for Basic react questions??
Mandeep Singhmar
Mandeep Singhmar

Posted on • Edited on

Basic react questions??

What is React?

React is a open source library built and managed by facebook used for building user interfaces.
React is declarative, means tell the react what you want and react build the actual ui.

Why does react need a root element?

Since, react is all javascript it needs an element where it can render it's own dom. and the react is all about javascript not anything related to html and the html tags we used in react called jsx not html.

Diff between state and props?

State is a way for component to store an internal state and you can store any kind of value in state.

props is where store stuff or value that is going to the next component or can say being passed to the component from the parent component.

What is context?

Context is a gloally available prop that should only be used on occasions when we need something that is going to be everywhere in application. for e.g user auth.

Which lifecycle event is the most common?

componentdidmount, componentdidupdate, componentwillunmount are the methods that we use most frequently in class based components but in the case of function based components we only need one hook
that is able to do the work of all these methods and that is useEffect.

The purpose of render function

The render function is used to update the user interface
It returns a single React element which is the representation of the native DOM component.
To render a React element into a root DOM node, pass both to ReactDOM.render()

What is component?

Components are the building blocks of any React application, and a single app usually consists of multiple components. It splits the user interface into independent, reusable parts that can be processed separately.

What is virtual DOM?

React keeps a lightweight representation of the real DOM in the memory, and that is known as the virtual DOM. When the state of an object changes, virtual DOM changes only that object in the real DOM, rather than updating all the objects.

Top comments (0)