useContext is a React hook for managing global state through the Context API.
Questions tagged [use-context]
586 questions
0
votes
1 answer
React.useContext and Minified React error #321;
I have a context:
export const AppConstArrays = createContext({
neededHours: [],
setNeededHours: (neededHours: INeededHours[]) => { },
serviceTypes: [],
setServiceserviceTypes: (serviceTypes:IServiceTypes[]) => { },
});
I am able to…

Ofer Gal
- 707
- 1
- 10
- 32
0
votes
1 answer
TypeError: Cannot read property 'map' of undefined - React app - useContext and useReducer issue
I am using react for making an app project using contextHook and reducerHook but getting:
TypeError: Cannot read property 'map' of undefined
The same code was working a few days back, but now it's giving that error. I've wasted so many hours…

Muhammad Daniyal
- 11
- 5
0
votes
2 answers
Cloned arrays affecting react state
I'm having issues with cloning arrays in my react application.
I import an array with data to my app called ApplicationsData. It's an array of objects.
import ApplicationsData from '../Store/Applications';
App component has the following…

Emil Østervig
- 440
- 4
- 20
0
votes
1 answer
React Native Context Content is keep Coming Back
I want to clear user and do logout in React Native using useContext, useReducer, and useMemo.
My App (AuthContext) has Users Screen (UserContext) in it.
UserContext has clearUsers() within useMemo
AuthContext has logout() within…

Jeaf Gilbert
- 11,495
- 19
- 78
- 105
0
votes
0 answers
Class based Context.Provider and UseContext working example
I came across a scenario wherein i was making an app entirely using React hooks.
I had to use certain NPM libraries in the app which were not hooks compatible. To avoid prop drilling, i plan to use useContext. Since some of my components which were…

ryan
- 694
- 9
- 23
0
votes
1 answer
While passing image via useContext from login and image is not displaying
During onSubmit in the Login, I did setLoginPhoto(res.data.photo)and then using useContext() to pass the photo information to Navigation. But apparently the photo information is getting clearing off once login is successful and displays the Home…

soccerway
- 10,371
- 19
- 67
- 132
0
votes
1 answer
Localhost storage
So the below code is how I'm trying to get localStorage to persist a user's state beyond a page refresh.
This essentially works on the homepage, wherein whenever I refresh I see that the localStorage does indeed persist even with a refresh.…

Karan Bhasin
- 237
- 3
- 13
0
votes
0 answers
How do we handle image with filepath and convert to base64 in react hooks
How do we handle and convert into base64, if we receive image with path in React Hook in following format: images\photo-1592376542020.JPG
UserLoginProvider.js
import { UserProfileContext, UserLoginContext } from '../context';
const…

soccerway
- 10,371
- 19
- 67
- 132
0
votes
1 answer
Values are not passing and displaying even after using useContext() in react hooks
I was using useContext() to get the values like name and photo in Navigation.js. I have set the in Profile.js. But still values are not displaying in Navigation.js >> …

soccerway
- 10,371
- 19
- 67
- 132
0
votes
1 answer
How to stop re-rendering when using useContext (Reactjs)?
I have a simple react app in which there is a FruitsList component for showing the fruits in the list, a FruitForm component to add a fruit, and both are contained inside a Fruits component. I am using useContext and useReducer to manage the state…

Uddeshya Kumar
- 41
- 5
0
votes
2 answers
React Context passing Time every second occurs infinite loop
Sorry I'm new to React, and so I faced a problem where I have my Context which provides the Time to other components. When I use it only with the component where I display my clock everything is fine. The problem occurs in another component, where I…

Dasha Tiunova
- 11
- 3
0
votes
1 answer
How do I use the Contentful api data with React Context API (useContext in particular)?
I'm trying to use a database I set up in a headless cms known as contentful. The problem is, all the tutorials I watched uses Class components to handle state. I learned useContext for the Context API method, which I find to be more appealing and…

FINAL BOSS
- 15
- 1
- 6
0
votes
1 answer
use context value as initial state value - react hooks
Can We use context values to initiate a state variable inside a function component?
Here I am trying to initiate a component state with values from context. But the state doesnot update when context value changes.
function Parent() {
return (
…

Jay Surya
- 540
- 1
- 8
- 18
0
votes
2 answers
Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is null
I'm getting the error "Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is null" when I use useContext() hook from react in Next.js.
// Other imports
import CurrentUserContext from…
user10261767
0
votes
0 answers
React useContext not triggering a re-render
I have set a three part Component for a filter menu. Component A) is the createContext which has an object with my globalData data and a function setData to change the data. When setData is triggered it retrieves data from the DB and updates the my…

suhail
- 43
- 4