DEV Community

AlaminHossain01052000
AlaminHossain01052000

Posted on

Basic About React jS

1.What is JSX is React
Ans:Full form of JSX is JavaScript XML. It allows us to write HTML in JavaScript without using the methods like appendChild(), createElement(). It is syntactic sugar of function calls.
A browser can not understand a JSX syntax. So we need a transpiler to make it browser compatible. Babel works as a transpiler and converts the JSX to an object tree.
The browser just receives the object tree and compiled it.

  1. Describe Component Lifecycle in React Ans: There are three phases in react component life. Mount: Birth of component Update: Growth of a component Unmount: Delete or death of a component A react component has to pass through these phases. We need some methods to mount, update or unmount a react component. Mount: render(), componentDidMount(), constructor() Update: render, componentDidUpdate Unmount: componentWillUnmount 3.Tell me about differences of State-props in React Scope: Props are passed in components like function’s parameter. State only works in a component like a variable. Immutable: Props are immutable. It means it is only read-only. States are mutable. Use in class components: props is used like this.props and state is used like this.state in class component. Use in functional components: props are used as props and state is used like useState in functional component. 4.What do you know about Virtual DOM and diffing- algorithm Ans: Whenever a React Js web application is executed a virtual dom is created in primary phase of its execution. New dom check the changes with previous dom.When changes is detected two virtual dom is compared using diff algorithm and finally it allows changes in real dom.
  2. What is Prop Drilling Ans: Passing parameters between components in react is possible in one way. A parent component can only pass a parameter to its immediate child component. But sometimes we need to pass parameters or props to many components. So here the word comes props drilling. Props drilling means not only passing data to a child component but also to other components. In react using context API we can easily pass data. There is a hook called useContext and method createContext and many other terms are used to props drilling 6.What do you mean by render() method Ans: render() method is used in every component of React Js. It returns the HTML which has to display in the UI. We only render a single element. If we want to render multiple elements we have to contain them in one parent tag. 7.What will you do to Prevent unnecessary component re-render Ans:Avoid changes in DOM tree structure. Using keys to prevent re-renders. Make sure that values are must not be changed. Using React.memo or React.PureComponent Use object as props
  3. What is PropTypes Ans: Generally we use props for passing data between one component to another.But sometime because of wrong props and error is occurred and we can handle it by using proptypes.

Top comments (0)