React Js
React Js
UseEffect
It is used to perform side Effects in a Functional Component , such as
Data Fetching , Subscription , or manually changing the DOM
It runs after every Render by Default but can be controlled by
Specifying dependecnies
UseRef
A ref is a way to access the DOM directly within React. It is used to
get a reference to a DOM element or a class component instance.
It allows us to create mutable varible which don’t cause re-renders
It is very useful to directly access dom element
Const variableName = useRef(InitialValue)
UseReducer
UseReducer is used to manage state in our React Application
It work like a state management tool
Always use the useReducer hook when you have a lot states
and methods to handle
const [state , dispatch] = useReducer(reducer, initialState)
UseLayout
UseLayoutEffect works exactly the same as useEffect (also the same
syntax)
UseEffect runs after the dom is printed on the browser
But useLayoutEffect runs before the dom is printed on the browser
You can use it if you want to run code before the dom is printed
Like if you want to measure height width anything related to layout
It runs line by line
The most common use of useLayout is to get the dimension of the
layout that’s why it is called useLayoutEffect
UseMemo
UseMemo hook is used to apply Memoization in React
Memoization is a technique for improving the performance of code
It is useful to avoid expensive calulcations on every render when the
returned value is not change
It is used to improve performance in our react application
We can stop running unwanted function on re-rendering
Const memoCalculation = usememo( callback , [dependency])
UseCallback