useContext is a React hook for managing global state through the Context API.
Questions tagged [use-context]
586 questions
0
votes
0 answers
How to give a function access to useContext (React native)
Basically I wrapped a Side Menu in a Provider and gave it menu of a function. Inside the side menu I wrapped stack navigation, so all my navigation screens have access to useContext.state. But my sidemenu's menu() has a problem with accessing…

Keti Sulamanidze
- 1
- 1
0
votes
1 answer
children with useContext() not rerendered with current value
I looked through all the posts with similar title but found nothing that helped me understand my issue and solve it.
I have created a context that passes down the state of a switch (toggled or not). Problem is consumers (children) are not receiving…

Chayemor
- 3,577
- 4
- 31
- 54
0
votes
3 answers
useContext - my parent does not render when i set state in the child
I am not that good at react js.. I just wanted to make a "Global value" to let the childs of that parent see that value so I found useContext that allow sharing values along. so I wanted to use (useState) so I can set it from the child so it…

Zeyad Alaa Eldin
- 9
- 1
- 5
0
votes
0 answers
how to useCallback in useEffect when fetching data in async mode
can any one help me with that
actually i am trying to add useCallback function but it's seems not working it's loading
not showing any data
every time i change page and came back to the "users" url it's start re-render
plz help me with this
plz if…

Frank Maruf
- 1
- 2
0
votes
1 answer
React-Native - my state being reset after adding values to the current from specific component (panResponder)
I have a component that I built with useContext.
The problem is that my State (named myCartItems) is always being reset and I don't know why. The idea is to add more elements by calling the function addToCart with a product id. then I am trying to…

Or Nakash
- 1,345
- 1
- 9
- 22
0
votes
1 answer
useContext Returning Undefined Even Though It Shouldn't Be Undefined
I have created the following context in React:
import { useBoolean } from "@chakra-ui/react"
import { createContext, FC } from "react"
type useBooleanReturn = ReturnType
export const MobileContext = createContext<
[show:…

Moshe
- 6,011
- 16
- 60
- 112
0
votes
1 answer
Create dynamic initial states for React useContext
I'm trying to dynamically initialize context based on a variable from within the context, the dynamic variable is an empty array of length N, where N=size which is part of the context.
I would like the default size to be 5 unless overridden in the…

ortunoa
- 345
- 4
- 11
0
votes
2 answers
how to execute on click function to show filtered results from search bar in react
I am working on a component where the user searches a term and it is returned to them through a filter. I am using useContext hook to pass data from db via axios. I would like to use the button in the CompSearch component to render the results…

Julie
- 484
- 7
- 22
0
votes
1 answer
Add new content to object
I'm facing some issue trying to stock data inside an array.
I've created a component input which I use many times. Each input stock different data about a user. I would like to format an object where all this information will be stock in a json…

samuel potter
- 189
- 3
- 13
0
votes
1 answer
React dark theme: setContext is not a function when accessing from useContext
I cannot seem to see what is going wrong here, pretty basic usage to useContext and useState hooks. I have a darkModeContext where I am literally just flipping the boolean for darkMode, but whilst trying to flip it for the context I am getting…

user2921885
- 159
- 11
0
votes
2 answers
useEffect infinite loop with useState
I'm trying to check if authState is true to show my side sidebar to the user. It works but I get an infinite loop.
here is the useEffect and useState
const [ authState, setAuthState ] = useState({
username: "",
id: 0,
status:…

madmeatballs
- 73
- 1
- 10
0
votes
3 answers
Dispatchs fire together inside UseEffect with Async function
There is a Profile component that creates a 3D face using an async function. To inform the user to wait, two dispatches is fired before and after the heavy task inside the UseEffect. The problem is both of these dispatched only fire after the heavy…

Saeid
- 83
- 8
0
votes
1 answer
React using useContext, ureReducer and useMemo: XXX is missing the following properties from type YYY TS2739 error
I am not an expert on React so asking here.
I wanted to create Application context with React.useContext API.
Here is my easy sample code here:
import {
createContext,
FC,
useCallback,
useContext,
useMemo,
useReducer,
} from…

user76333
- 153
- 1
- 13
0
votes
1 answer
Can't delete an item using useContext and useReducer
Please help guys. So I've started to learn about useReducer and useContext and I'm stuck at deleting an object. I've tried to log the result in the console and it prints the expected array that I want. However, when I return the array from the…

XypriL
- 129
- 1
- 1
- 9
0
votes
1 answer
Creating a React Context with TypeScript to share state
I am trying to create a React Context with TypeScript to share state between components. When creating the Context, I tried passing null as the initial value.
// contexts.ts file
import { createContext } from 'react';
export const AuthorContext =…

axtck
- 3,707
- 2
- 10
- 26