Questions tagged [use-context]

useContext is a React hook for managing global state through the Context API.

586 questions
-1
votes
1 answer

React context state is not being updated

I have a next.js app where I am trying to use react context to export a state. However, the state is not updating and remains as the initial value set by the createContext hook which is undefined in this case. Am I doing something wrong? This is the…
Anonymouse
  • 91
  • 1
  • 7
-1
votes
2 answers

Flatlist doesn't display the list from useContext

In react native app, I have a home screen and a second screen that the user uses to add items that should be displayed on the home screen. I am using context to save the list of items. The problem is when I add items to the second screen and go to…
-1
votes
1 answer

React Native Render Error undefined is not an object (evaluating '_useContext.register')

My useContext look like is work but when i chnage screen to SignUpScreen it give me Error like this Render Error undefined is not an object (evaluating '_useContext.refister') here is my SignUpScreen.js import React, { useContext, useState } from…
-1
votes
1 answer

Dispatch action from componentWillUnmount()

I am creating a Multi part form as below,
-1
votes
1 answer

_React$useContext is undefined on app.js component

I'm trying to useContext on the file app.js but I receive an error: _React$useContext is undefined Normally, I wrap correctly the only component I have, but it tells it's undefined (I saw few answers before asking, some of them tells it's because…
Bpio
  • 23
  • 4
-1
votes
1 answer

React gives wrong index to Child with React.memo

I've got a problem in my project which is pretty large therefore I can't post every part of the code here, but I'll try to summarize the main parts. I've got a parent component which state is managed through a useReducer and which render returns a…
Fsanna
  • 347
  • 1
  • 4
  • 11
-1
votes
1 answer

React TypeScript UseContext with complex type does not work

The ThemeContext example from this link works, but it only serves one field. I tried to use this example for a complex type UserContext. The state is set, but not rendered. I published the codesandbox example. The first button toggled the state…
Alligator
  • 250
  • 1
  • 7
  • 14
-1
votes
2 answers

react hooks context state is undefined when refreshing the page

I am creating a social media app and when I log in with the user, I'm saving the token in the local storage and also putting in context the user's information to use it in several components after, and its working, but when I refresh the pages, the…
-1
votes
2 answers

useEffect infinite loop network request

I am getting infinite requests on my network, and it's due to my useEffect. I know that the problem is because I am putting in the brackets as the second argument the 'posts' and the 'setPost' inside the useEffect function, but I need the page to…
-1
votes
1 answer

Trying to convert into typescript..cant figure out how to make action types and payload..i am using useContext and use Reducer

Trying to convert into typescript..cant figure out how to make action types and payload..i am using useContext and use Reducer i basically want my action to get types from the key of ./types that is provided and laso figure out the way to provide…
tanmay
  • 39
  • 1
  • 8
-1
votes
1 answer

Unable to destruct the passed values in the context provider using 'useContext' hook

code in sandBox : https://codesandbox.io/s/goofy-dhawan-n2kk2?file=/src/components/NavBar.jsx Error: TypeError: Cannot destructure property 'books' of 'Object(...)(...)' as it is undefined.
Sam AlGhamian
  • 73
  • 2
  • 12
-1
votes
1 answer

why when using hooks do i get this error "Hooks can only be called inside of the body of a function component."?

Every time I run yarn start with the following line of code const context = useContext(GlobalContext); I run into this "Error: Invalid hook call. Hooks can only be called inside of the body of a function component." How can I fix this it's driving…
lukeet
  • 461
  • 1
  • 4
  • 22
-1
votes
2 answers

Dynamically update context in React Native hook

I am trying to update theme of my react native app using context API but it is throwing an error setThemeMode is not a function. (In 'setThemeMode(themeMode === 'light' ? 'dark': 'light')', 'setThemeMode' is "i") I have taken refernce of following…
-2
votes
1 answer

Why use Redux / useContext when there are localStorage / sessionStorage already?

The point of redux and useContext is so that state variables can be persist and be shared across components. localStorage and sessionStorage already do this. So what does redux and useContext add that aren't already present?
-2
votes
1 answer

Where should I save API information in React?

I'm beginner to React and It seems that there's convetion like creating separate folders and files for UI, NavBar, Landing page etc in React. In which component do people usually store URL and API key information in React? I assume that It'd be the…
Hans
  • 49
  • 1
  • 7
1 2 3
39
40