You are on page 1of 10

WHAT IS

REACT
CONTEXT
API?

@codewithatia
Context API
In simpler terms context API
is state management tool

It helps in managing state in


entire app without using
props

@codewithatia
If your're confused what
state is check one of my
posts called "useState"

@codewithatia
How it works?
All we need is to call
React.createContext(), it
returns provider & consumer

Provider Consumer
It provides It's used to
state to it's consume
children data.

@codewithatia
Here're 4 steps to use
context API

1. Create Context

2. Wrap in Context
Provider

3. Provide value

4. Read value using


consumer

@codewithatia
Let's build a
simple app to
understand
context API

@codewithatia
Create Context

First step is to create


context

@codewithatia
Wrap in Provider

Wrap context in
provider &
also provide value to
context

@codewithatia
Read Value

we can read context


value using any of the
above way

useContext is simpler
to use

@codewithatia
Found it helpful? Follow for more

Need my help?

Need a website or mobile app developer?

Have an App idea? Let's do it together

DM for free consultation

@codewithatia

You might also like