useContext is a React hook for managing global state through the Context API.
Questions tagged [use-context]
586 questions
0
votes
1 answer
How to make a page free of authentication using react context?
I have just one page that should be open access to everyone who access to the application URL, but the useEffect of the AuthContext is firing without being called. I'm new with Context Api, anyone know what is wrong ?
The route that should be open…

Donada
- 298
- 1
- 9
0
votes
1 answer
A mistake causes the function to be rendered infinity
I tried to add a button to my code, To change some properties of an array by clicking on it. To do this, I used Context and Reducer. But there is a problem!
When I comment the dispatch, the problem is solved and the function is rendered only once.…

PariParia
- 47
- 1
- 7
0
votes
1 answer
How trigger function after react context hook updated
I'm trying to call a function after the "context hook" from react is updated. Tried the code below:
const MyComponent = () => {
[context] = useContext(MyContext);
function updateContext():void {
context = "someNewContext";
}
…

Iara Nascimento Sztybe
- 31
- 1
- 4
0
votes
1 answer
React context object does not seem to be updating properly again
I am trying to use context API object in my component and update the same context object twice (once during initial component load and other on cell click)
For some reason, when I update it on cell click and console out the value, it still has the…

copenndthagen
- 49,230
- 102
- 290
- 442
0
votes
1 answer
React initial value of createContext is used instead of provided one
I'm creating a Context with the boolen isDark inside my App. The boolean isDark is created with useState and I provide this boolean and a function to change the boolean to a ThemeContext to access it further down the component tree.
Down below I'm…

JonasLevin
- 1,592
- 1
- 20
- 50
0
votes
0 answers
useContext triggers rerendering without changes
I have following react-component:
type Props = {
country: string;
electricityValues: number[];
activeStep: number;
setActiveStep: React.Dispatch>;
}
const EmissionsMemoized = (props: Props) => {
…

Hans
- 1,162
- 11
- 18
0
votes
1 answer
How can I render with useEffect?
Well, I want to make a feedback section, in which the system asks if the post helped the user and the user can vote to "Yes, it helped me!" or "No, it didn't help me". If his vote goes to "No, it didn't help me", he must specify the reason why it…

Fernando Ferreira
- 41
- 1
- 7
0
votes
1 answer
useContext working not working with nested component
I am trying to refactor an app to use useContext but have hit a snag and cannot figure out what is happening.
Using the latest version of everything, running Next.js.
The way things are structured is that every page is wrapped in and some…

Zeb
- 547
- 4
- 15
0
votes
0 answers
How to do POST request that requires dynamic variable in Next.js by Server Side Rendering?
I'm using Next.js framework and made a simple web application.
Using Firebase Auth, I tried to manage only authenticiated users to send requests. So basically, I need that user's id token. But as you know as user.getIdToken() doesn't work because…
user14372603
0
votes
2 answers
How to wait until state in useContext is completely loaded?
I want to populate the input field initially with the fullname value available in "state". But I am getting TypeError: Cannot read property 'fullname' of null error when I reload the page, since the state is not yet loaded at that time.
function…

Sathishkumar R
- 13
- 4
0
votes
1 answer
How to reach a Context API method inside of a helper function?
I created a file which would contain helper functions for querying the database. My problem is that I have to get my access token through the Context API but I can't call the useContext hook outside of a functional component. I could place the…

spaceBar
- 1
- 3
0
votes
0 answers
Jest useContext return value function is not a function
I'm new to jest and want to write my first tests, where I want to test a slide change in my swiper. The onClick on my next-slide button has a callback function that comes from a react useContext.
When I run my test, i get this error:
SwiperComponent…

f.g.
- 93
- 1
- 7
0
votes
2 answers
React: How to make store invulnerable for reload?
I created store with useReducer, and provide state and dispatch function by Context provider:
/*code...*/
import { InsuranceItemContext } from './Context/InsuranceItemContext';
import { reducer } from './Reducer/Reducer';
function App() {
const…

Iangyl
- 69
- 11
0
votes
4 answers
How to pass a value using `createContext` from parent to child's child component?
Instead of passing props from parent to child1(parent of child2) ->to child2,
I want to use createContext and receive the value with useContext.
What I tried to do is not correct because and I'm getting an error **'booleanContext' is not…

ExtraSun
- 528
- 2
- 11
- 31
0
votes
1 answer
Function passed as context value can't access updated component state when called by a consumer
I am passing a function to as value to the Context Provider and on calling that function from the consumer, I'm getting the older state.
Provider.jsx
const MyContext = createContext();
const Provider=()=>{
const [someState, setSomeState] =…

Madhur Bansal
- 726
- 2
- 8
- 14