useContext is a React hook for managing global state through the Context API.
Questions tagged [use-context]
586 questions
1
vote
0 answers
Reactjs - infinite loop using useContext hook with conditional statement
Here is my code:
App.js
import React from "react";
import Child from "./Child";
import { VariableCreator } from "./Context";
const App = () => {
return (
);
};
export default…

wongwong3000
- 29
- 6
1
vote
1 answer
When does useEffect call when I use it with useContext?
I call useEffect inside useContext and I want to know when this useEffect is called.
[settingContext.tsx]
// create context object
export const ColorContext = createContext(null);
export const ProductsProvider = (props) => {
…

Yuzu
- 59
- 1
- 8
1
vote
1 answer
React: Form submit must be clicked twice to set context globally using useContext
React Beginner here. I'm building a login form in React using jwt, axios and useContext. After being authorized from the backend, I store the data in the global context using AuthProvider and redirect to home page. the home page first checks for…

Nugget
- 81
- 1
- 6
- 23
1
vote
0 answers
React Context does not work in Netlify. TypeError: Cannot read properties of undefined
I am having this issue every time I deploy my react application to Netlify:
The code works locally however, once deployed to Netlify it generates the above error.
Here is my Code:
import { createContext } from "react";
import { languageOptions,…

user18533851
- 31
- 2
1
vote
1 answer
React useContext() always returning initial value in different children
I need to share global variables through multiple components, and it seems that my context is not working as expected.
I declared in a seperated file globalContext.tsx :
export type GlobalContent = {
entities: entity[]
setEntities:(c: entity[])…

Bababibel
- 13
- 3
1
vote
1 answer
useContext returns undefined (React Native, Expo)
I am trying to retrieve user data(name, email) to display after I login but I keep getting undefined but whenever I console.log( user ) I see all the data including the name and email
Context.js
import React from 'react';
const AuthContext =…

delle
- 213
- 3
- 15
1
vote
1 answer
Prevent re-rendering of whole application when context value changes
I have an application where user has lot of profile information e.g LinkedIn profile. I need to update user's profile.
I create a context at root level component i.e App and share that context using useContext hook in multiple profile…

Hammad
- 2,097
- 3
- 26
- 45
1
vote
1 answer
React hook unable to be called inside of class component
just wondering how I can fix this? I heard about using consumers but I don't think this will resolve the issue, since I need to call setSaveEnabled in the handleChange() function, which cannot be defined inside of a consumer if I were to make one.…

jaal kamza
- 213
- 4
- 12
1
vote
3 answers
React js context api is not woking how to fix it?
I'm was making the shopping card Project and I decide to use Contextapi and useReducer for my state management at the start of my project I wrap the App in context Api and it crash my App Here is the Code.
****Main Index *******
import React…

z Hunter
- 31
- 4
1
vote
1 answer
Typescript Type of React useState second parameter
i am trying to apply typescript on my react javascript project
i used createContext() to pass useState() parameters
and applying typescript, he rages because of lack of first value in createContext()
also i am not sure what type i should put for…

koreachief
- 13
- 3
1
vote
2 answers
ReactJS giving error Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0__... is undefined when implementing Context API
I'm using Context API for a cryptocurrency tracker app. What I want is to create the state currency and setCurrency from the context named CryptoState which I created in CryptoContext.js and import to Header component so I can use them to do the…

Lawrence
- 25
- 1
- 6
1
vote
3 answers
React context not shared between components
I use a react context between 2 components, however when I set the value this context in the child filtersBar component, it does not update or useffect in the second child map component.
contextprovider
const SearchContext = createContext();
const…

a-dawg
- 783
- 1
- 5
- 13
1
vote
2 answers
Prevent refresh while using useNavigate from react-router-dom
I am trying to keep some values using useContext API while moving with navigate("/toLocation") (let navigate = useNavigate()) but it refreshes and clears the value.
How do I use useNavigate and still keep the value in my context api
const…

SMTP King
- 429
- 3
- 12
1
vote
2 answers
Creating hook in Typescript with useContext and empty context object
I'm trying to create a useAuth custom hook within React 17 and Typescript. The solution that I have is kind of working, but it requires the following when accessing the hook methods:
const auth = useAuth();
// Do other stuff
const result…

Juzzbott
- 1,737
- 2
- 25
- 44
1
vote
0 answers
Updating array context state in component updates strangely
I have a brand filter toggle that when it is triggered it adds or deletes a element to a brand's array and then in my context when i detect that the brand's array changed i make a second api call to add the brand filters to my api call.
And the…

Mat
- 119
- 1
- 11