Questions tagged [use-context]

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

586 questions
1
vote
3 answers

How to remove a slice / reducer in a redux store?

In the register component of my APP, the state is stored in a redux slice. After the user registers, this component will never be rendered again and thus the memory in its redux slice should be freed up for performance. How can this be done?
1
vote
1 answer

would redux trigger re render if a nested property is updated?

export const userSlice = createSlice({ name: "user", initialState: { info: { dob: null, } } }) What if the dob property is updated but the reference that info is pointing to is not changed? Would this cause a component which…
1
vote
0 answers

usecontext without child component?

I'm wanting to pass a state from my WeatherComponent through to my UserForm component and ideally would like to do this without making the UserForm a child component. At the moment I have the UserForm as a child component and that component is…
1
vote
1 answer

Update parameters value between screens in react-native

in my 2 screens react-native app, I'd like to know which is the best way to do the following: In the main screen, a simple Text component shows "Hello" and a button that leads to a screen that shows "Hello" in an input field and a "GoBack"…
1
vote
1 answer

How to create Private Routes with firebase v9 reactjs

My problem is that the moment i navigate to the homepage and the user is not authenticated the page shows for a split second and then move on to the login page. I want it to redirect to login only and not show the homepage for a split second I…
1
vote
0 answers

How to fulfill React useEffect missing dependency requirements?

I can't figure out, how to fulfill the useEffect missing dependency requirements in the Dashboard component, where I only want to fetch Jobs once on render. Adding fetchJobs as a dependency or removing the dependency array causes infinite…
1
vote
1 answer

setState inside useEffect cause infinite loop

I want to use the list to seData and setUserData. I am using data to map through the list of users and display on the table. I am using the userData to get user information in different components. This is causing infinite loop. import { useState,…
1
vote
1 answer

Create array from State grouping IDs

I'm building a shopping cart, and my cart products array comes from a state. When I press the 'add to cart button, this function occurs(Infos is where the product Infos are): const [cart, setCart] = useState([]) function addToCart() { setCart(…
unknwDev
  • 29
  • 3
1
vote
1 answer

Updating Parent Component using useContext

I'm trying to change the state of a parent component from a child component. My Component structure is basically like this.
jmsapps
  • 388
  • 2
  • 17
1
vote
1 answer

React custom hook with useContext functions

when i try to use a function inside a custom hook the following error happens: Uncaught TypeError: tglCartao is not a function my custom hook at UseCartao.tsx: export interface ICartaoContext { idToggleKey : string; setIdToggleKey? :…
1
vote
2 answers

ReactJS UI Does Not Update The State

I am trying to make a simple e-commerce app. When a user goes to cart section and try to increase or decrease quantity, it changes the state but remains same on the page. I need to go back and go cart again to update. How can it change…
1
vote
1 answer

Uncaught (in promise) Error: Invalid hook call. - SPECIAL CASE

I know that hooks cannot be called from functions other than React Functional Components, this is a bit different. I have created some utility/service type functions that need to use hooks. // somewhere in services files... const utilNavTo = (route)…
M.Imran Mamda
  • 394
  • 1
  • 2
  • 13
1
vote
2 answers

undefiined useContext destructure

i am trying save user object in context but i am gettin g undefined this is my context: import { createContext } from "react"; export const UserContext = createContext(null) this is routs : import { UserContext } from…
saeed
  • 69
  • 1
  • 9
1
vote
1 answer

React useReducer bug while updating state array

I haven't been in React for a while and now I am revising. Well I faced error and tried debugging it for about 2hours and couldn't find bug. Well, the main logic of program goes like this: There is one main context with cart object. Main property…
Nijaz
  • 168
  • 2
  • 11
1
vote
1 answer

TypeError: Failed to execute 'fetch' on 'Window': Invalid name

am trying update my todo list in my project using useContext api, i want to remove completed if i click of input checkbox but whenever i click on it am getting this error TypeError: Failed to execute 'fetch' on 'Window': Invalid name at _callee$, i…
Emmanuel uzoezie
  • 433
  • 1
  • 5
  • 18