useContext is a React hook for managing global state through the Context API.
Questions tagged [use-context]
586 questions
0
votes
1 answer
Reducer payload of array with new order does not update the state
First of all, here is a CodeSandbox: https://codesandbox.io/s/todolist-reducer-0y3mb?file=/src/context/TodosReducer.js
The problem is that the state is not updating even though I'm passing a payload with a new array to the reducer.
I'm rearranging…

Mattias Bregnballe
- 101
- 6
0
votes
1 answer
Update useContext using response from axios
i want to update the context form a response using axios so i can use it in another component on another page
const search = (min, max, l, r) => {
if (min == null) min = 0;
if (max == null) max = 2000000;
if (l === "") l =…

Luciano Bicaku
- 11
- 2
0
votes
1 answer
useContext value changes on rerenders
So I have a component that looks something like
const App = () => {
const someContextValue = useSomeContext(); //custom hook that calls useContext
useEffect(() => {
someContextValue()
}, [someContextValue]);
return

Sreya Rajendran
- 13
- 5
0
votes
1 answer
Initialize state in async function within context/provider react native
I am using Context Hooks to work with states within react native. I would like to initialize the state via a async function doing an API call and then return the initial state via useState. Thats my try to set the initial state for…

theGermanJorge
- 15
- 1
- 5
0
votes
1 answer
UseReduce Hook dispatch twice-ReactJS
I develop a small application with the purpose of studying react hooks. The application consists of writing the name of an artist in a section. In the next section, a similar form, to fill with albums of each artist.
I have all my components…

David Sabillon
- 11
- 4
0
votes
1 answer
createContext hook not working for react components inside JSP
I am rendering my react component inside an existing JSP page using
ReactDOM.render(
React.createElement(MyReactComponents.myReactComponent, {
props
}),
document.querySelector("#id")
);
and the react component is as…

Novice_Developer
- 39
- 5
0
votes
2 answers
Correct way to use useEffect() to update when data changes
The useEffect below renders, fetches data, and displays it once (using an empty array for 2nd parameter in useEffect).
I need it to rerun useEffect everytime the user changes data to the database (when user uses axios.post).
What i've tried
using…

tonytone
- 37
- 1
- 5
0
votes
1 answer
target DOM element with React.createPortal
I would like to get the innerHTML of a div with the className "editor" which i am passing in through useContext. Once I receive the innerHTML, I will append it to a div with the className "getcontent". Currently, my code is giving me an error…

user3574939
- 819
- 3
- 17
- 34
0
votes
1 answer
My component can't read property in first render but in the second render my property , it will already have
This is my error
TypeError: Cannot read property 'email' of null
This is my provider component
import React, { useState } from 'react'
import { whatchUserChanges } from '../services'
export const AuthContext = React.createContext()
export default…
0
votes
1 answer
What’s the most efficient method to drag/move objects simultaneously?
This is more of a general design question than a specific question about a piece of code. Let me do an outline:
Imagine a canvas with a poly line consisting of 3 or more points. Each of those points has a circle object as draggable handle. The user…

genox
- 23
- 6
-1
votes
1 answer
I can't use useContext with Typescript with my react application
I am new to typescript and trying to build a Todo app with the use of 'useContext' hook using typescript-react.
I am not able to pass TodoContextProviderProps as a prop below, to my Provider function.
import React, { FC, createContext } from…

Gourav Kumar
- 77
- 6
-1
votes
2 answers
Using both redux and useContext in your react app
Are there reasons why one would use both redux and useContext in their APP?
If so, what are they? Can you give examples of when to use either?

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
-1
votes
3 answers
How to conditionally render a component in react.js?
I am new to React and for my first project I'm trying to build an expense-tracker, by Traversy Media on YT.
I've thought to expand project a little bit by adding a date component to it. My current output looks as follows: Image 1
And I want to look…

अंशुल
- 49
- 6
-1
votes
1 answer
Can a Reactjs `Context` have multiple providers?
I wonder if I can have multiple to provide the value for a Context. I'd like to have multiple components (the contents of various pages) provide values such as the page title to a topbar.
Is it possible? Thanks

JavierG
- 201
- 4
- 12
-1
votes
2 answers
State is always undefined in nextjs useReducer and useContext
I am using context api in my nextjs project but whenever i am trying to get value from state using context api it is always throwing error "undefined"
AppReducer.js
const initialState = {
isMobile: false,
user: {},
};
export const…
user18052819