Context:
Context provides a way to pass data through the component tree without having to pass props down manually at every level.

Example:

lets take a example where

  1. AppComponent (root component).
  2. ComponentC ( Nested inside root component).
  3. ComponentE (Nested inside ComponentC ).
  4. ComponentF (Nested inside Component E).

prior to Contex API ,if I want to pass a data from App component to component F then we need to pass data from AppComponent to component c in props and from component c to component E and component E to F.

These props drilling can be avoided by using Context API.

There…


useEffect:

There are different variations in useEffect.

let's take a sample example of useEffect, where there is no dependency to useEffect.

useEffect(()=> {
document.title= `Clicked ${ counter } times`;
});

when ever a state changes in component, component will re-render.

What does state changes in component mean ?
Components will have many states, if any of the state changes then the component will re-render and if there is no dependency in useEffect, then it will be executed everytime.

useEffect hook when used without dependencies runs after every render of component that means once the state is changed component will be…


Hooks are new feature added in React 16.8 version by which we can use react features without classes
Hooks wont work inside class, Hooks should be used only in functional components.

Rules of Hooks :

  1. Hooks should be used only at top level of component.
  2. Hooks should be used only in React functional components.
  3. We should not call Hooks inside Loops , Nested functions.

useState Hook:
If our business logic depends on some state, then we can make use of useStateHook.

useState will return two parameters.

  1. current state.
  2. function by which we can update that state.

useState will take…

prashanth palakurthi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store