Logo InterviewVault

Welcome back, Sujit Kumar Mishra

SKM

Revision Mode

Document technical questions and best-practice answers.

Cancel

What are the major functions you have used in ReactJS? Can you explain those uses in detail? 

The major functions I use in ReactJS are:


1: useState()

This function lets us add state to our components.

Example: We use it to store and update values like user input or a counter.


2: useEffect()

This function helps us run code when the component loads, updates, or unmounts.

Example: We use it to fetch data from an API or set up subscriptions.


3: useContext()

This function lets us use data from a context without passing props manually.

Example: We use it for things like user authentication or theme settings.


4: useRef()

This function gives us a way to access and store a value that doesn’t cause re-renders when changed.

Example: We use it to get a reference to a DOM element or to keep a mutable variable.


5: useMemo()

This function helps us optimize performance by “remembering” the result of a calculation until its dependencies change.

Example: We use it to avoid recalculating expensive operations on every render.


6: useCallback()

This function returns a memoized version of a function, so it only changes if its dependencies change.

Example: We use it to prevent unnecessary re-renders of child components that use callback functions.


In summary:

- useState for storing values,

- useEffect for side effects,

- useContext for shared data,

- useRef for references,

- useMemo for memoizing values,

- useCallback for memoizing functions.


These functions make React apps interactive, efficient, and easy to manage!

Ready for commit