Lets Talk About the React CONTEXT API!! | State Management Solution!!!

Vikram Nayyar CS
2 min readJul 26, 2021

Intro:

Following on from last week’s post about the ‘useRef’ hook, I thought it would be good to move away from ‘hooks’ (just for now!!) and focus on the React Context API.

This is a valuable, state management tool that helps to solve ‘prop drilling’ (a common development issue).

Again, the React Docs are a great place to find out more!!

I’m just aiming to boost my own, theoretical understanding of React and to then deliver it to you!!!

As always, before we get into the post; make sure to applaud and share this post with your friends!!!

What is The React Context API:

As stated above, it’s a solution to prop drilling.

We essentially create some global state for our React app, rather than passing down the tree of components. This makes it easier to share data with components.

When to Use It:

You should use it if you have data that is ‘global’ for the whole React app.

How to Use Context:

  1. ) Create the context (instantiate the context object).
  2. ) Create the State Provider.
  3. ) Wrap the app in the State Provider.

Final Things:

This is such a big topic that I would highly recommend that you look at the docs!!!

As always, remember to applaud and share this post, helping it reach more people!!!

Follow Vikram Nayyar CS on all platforms!!!

Hashtags:

#computerscience #coding #programming #technology #python #programmer #computer #developer #tech #coder #java #javascript #code #codinglife #webdeveloper #softwareengineer #html #machinelearning #softwaredeveloper #programmers #software #engineering #linux #programmingmemes #artificialintelligence #datascience #computerengineering #cybersecurity #hacking #bhfyp

Final Things:

--

--

Vikram Nayyar CS

Computer Science Student | Digital Content Creator!!