React Hooks Interview Questions
React Hooks Interview Questions
● UseState
○ Functional components to manage state in local state.
Syntax:
const[state,setState] = useState(initialstate);
● React components lifecycle in hooks
○ useeffect
● Useeffect
○ perform side efeects like Data fetching, subscriptions or manually
changing the dom
○ [] it should run only once
○ Include variables means it chn]ange wheneve it change
Syntax:
useEffect(() => {},[dependencies])
Usememo
Returns a memoized value.
performance optimization
Usecallback
returns a memoized version of the callback function that only changes if one of
the dependencies has changed.
useful when passing callbacks to child components
Prevent unnecessary re renders
Useref
reference a value i.e pointing out the reference like object
Usecontext
Usereducer
Alternate to usestate for managing more complex state
Takes reducer function and initial state then returns current state and
dispatch function