React Context API Alerts from others

So here is the situation, I have two React Context’s with the following reducers cases called by respectable actions





So what I want to do, if there is a way that I can call the SET_ALERT from AuthContext? Or a better workaround than I have here, maybe a pattern that I don’t know of.

I am not looking for code answers, but a simple 1 sentence is good enough or any suggestions you may have.

hey @razzakammar_nano,

im not quite sure what your asking , i got no clue what your AuthContext looks like, is SET_ALERT a reducer function that you want to use in a react component?
what i do is send the reducer dispatch down the context as a function so i can use it in any react component with the useContext hook.

As long as the AlertContect provider is above the AuthContext provider in the component tree, then you can directly access it. So it’s not a workaround: it’s the point of the context API – as long as the dispatch function is referenced in the AlertContext’s value prop, then you can get at it

1 Like

@DanCouper oh yeah i get what he was asking now he wants to access one context from the other, sorry @razzakammar_nano lol

@biscuitmanz @DanCouper I decided that redux will better fit my needs for my application, it is quite a large one so would be best to use Redux.

1 Like

yeah it will probably benefit you too learning redux if your looking for react jobs mate, it uses a few of the same things like dispatch and reducer anyway so if your used to that you should pick it up pretty quick

1 Like

I actually already know Redux, and I am only 15 btw.

I just prefer to use React Context API.

1 Like

your only 15? good time to start mate and if you already know redux your well ahead son, good man

Yep. Btw, Programming will be side hobby only, my main profession shall be anything in the Medical Field.

you going for a phd?

Yep. Will be definitely.

1 Like