Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

react(1)

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

1. What is React? Why use it?

React is a JavaScript library for building user interfaces, especially single-page


apps. It helps create fast and interactive UIs with components.

2. What is the virtual DOM?


The virtual DOM is a lightweight copy of the real DOM. React uses it to update only
the parts of the UI that changed, making updates faster.

3. What are components in React?


Components are building blocks of a React app. They are reusable pieces of UI like
buttons or forms.

4. Difference between functional and class components?


Functional components are simple JavaScript functions used in later versions of
React. Class components use ES6 classes and have access to lifecycle methods, and
were generally more common before React 16.8

5. What are props? How are they different from state?


Props are inputs passed to components from parent components. State is internal
data that can change within a component.

6. What is JSX? Can browsers read it?


JSX is a syntax extension of JavaScript that looks like HTML. Browsers can’t read
JSX directly; it needs to be compiled to regular JavaScript.

7. What is state in React?


State is a special object used to hold data that can change over time and re-render
the component when updated.

8. What are React hooks?


Hooks let you use state and other React features in functional components.
Examples: useState, useEffect.

9. What are the rules of hooks?


Hooks must be called at the top level of functional components and only in React
functions (not in loops or conditionals).

10. What is useState?


useState is a hook that lets you add state to functional components. Example: const
[count, setCount] = useState(0);

11. What is useEffect?


useEffect is a hook for performing side effects (like data fetching) after
rendering. It runs after the component mounts or updates.

12. What is useContext?


useContext allows you to share data between components without prop drilling
(passing props down multiple levels).

14. What is useRef?


useRef creates a reference to a DOM element or a value that persists across renders
but doesn’t cause re-rendering when changed.

15. What is React.memo?


React.memo is a higher-order component that prevents unnecessary re-renders if the
props haven't changed.

16. What is lazy loading in React?


Lazy loading delays loading components until they are needed (e.g., when the user
scrolls to them). Use React.lazy() and Suspense for this.

17. What is the Context API?


Context API allows you to share state globally across components without passing
props manually at every level.

18. What is the difference between Redux and Context API?


Redux is more powerful for large apps with complex state, while Context API is
simpler but suitable for smaller apps or specific use cases.

19. How do you handle events in React?


React handles events similarly to HTML but uses camelCase syntax (e.g., onClick
instead of onclick). Events in React are synthetic events, a wrapper around browser
events for consistency across browsers.

20. What are controlled and uncontrolled components?


Controlled components are form elements where React manages the state. In
uncontrolled components, the DOM manages its own state.

21. What is an error boundary?


An error boundary is a React component that catches JavaScript errors in its child
components and displays a fallback UI instead of crashing the app.

22. What are higher-order components (HOCs)?


A HOC is a function that takes a component and returns a new component with added
features (e.g., handling authentication).

23. How do you optimize a React app?


Common optimizations include memoization (e.g., using React.memo), lazy loading,
code splitting, and using the useCallback and useMemo hooks to prevent unnecessary
re-renders. generally these techniques applicable only in older version of react
because in later version we don`t have to implement these features react will
automatically take care it

24. What is React Router?


React Router is a library for handling navigation and routing in React apps. It
allows for multiple views in a single-page app.

25. What is SSR (Server-Side Rendering)?


SSR is when HTML is rendered on the server and sent to the client. This improves
SEO and load time compared to client-side rendering.

26. What is React Fiber?


React Fiber is a new algorithm in React 16+ that makes rendering more efficient and
allows React to pause and resume rendering work.

27. How does the virtual DOM improve performance?


The virtual DOM allows React to make updates faster by comparing the previous
virtual DOM with the new one and updating only the necessary parts of the actual
DOM.

You might also like