3,605 questions
Advice
0
votes
4
replies
62
views
How to access React context for base URL when creating Redux-Toolkit Query API slice?
I am trying to move to RTK Query, but am struggling with one thing - how to access React Context.
I currently am using custom hooks to query a back end. Depending on the environment (dev, uat, prod), ...
0
votes
1
answer
77
views
useContext in TypeScript
import { createContext, useContext, useState, useEffect } from 'react';
import { Appearance } from 'react-native';
import { lightTheme, darkTheme } from '../utility/theme';
type ThemeType = typeof ...
0
votes
0
answers
40
views
Auth context automatically redirect to homepage in case server returns error
if I login with wrong username or password the server (NextJS) will return error message with status code 401, what should happen in this case is that !res.success will be executed and it's indeed ...
0
votes
1
answer
80
views
Does the react context API not hide dependencies?
When I make a component that relies on something like the currently chosen language for example, or maybe a special query function to fetch data, and I provide either of these things via a ...
0
votes
1
answer
51
views
useContext does not show/update the value
I need to save the ID of a field from the settings.tsx view. That value need to be used with other view, like stations.tsx, alarms.tsx, map.tsx.
If later, I need to watch another field, I can change ...
1
vote
1
answer
76
views
If a child component consumers a context provider, do its parents also re-render?
Although the docs for context say "React automatically re-renders all the children that use a particular context starting from the provider that receives a different value.", from my testing ...
2
votes
1
answer
74
views
setState function not recognized as function
In my React Native app, I'm having a problem where the setState function is not being recognized as a function.
I already inserted the context provider on the App root page and exported the context ...
1
vote
1
answer
75
views
State updates causing excessive re-renders in complex React dashboard with nested components [duplicate]
I'm working on a complex analytics dashboard built with React and TypeScript, which involves multiple nested components. I'm using a combination of state management techniques including React Context, ...
-1
votes
1
answer
46
views
useContext data is not updated with latest state when changing routes
I created an auth context and set the object to an initial state, then after wrapping the App() with the provider, I am trying to modify the authContext in 1 (Home.js) component and then try to access ...
0
votes
0
answers
142
views
react oidc context signinpopup always returns an error that the pop up was closed
I'm using import react-oidc-context to auth with my aws cognito.
I'm trying to use the .signinPopup function but whenever the pop up opens I'm getting an error "Popup closed by user" ...
-1
votes
2
answers
182
views
Why is the state within a react context always the initial state
Original Question
I am trying to learn more about the inner workings of React, and here specifically Context Providers so I don't have a use-case in mind, just trying to understand why it works the ...
0
votes
0
answers
77
views
Where is the context state set in React Context?
I've created an app that stores user information in firebase.
The main profile page consumes the data via a hook that retrieves the data from firebase/storage. What I'm trying to do in this page is ...
0
votes
1
answer
115
views
Fetch user data once loaded Next.js
I'm attempting to fetch the data from user once the page loads.
Although, currently when there is any route changes, it triggers my useEffect and calls the fetch user endpoint which causes my loading ...
1
vote
0
answers
47
views
How to Share a Provider Across Isolated Components?
I'm working on a framework that allows developers to create extensions for a main app. Extensions can add components to different parts of the app layout, such as the sidebar or workspace, ...
0
votes
1
answer
31
views
React useContext method
I created a NewsContext for my React project for accessting static data:
NewsContext:
"use client";
import { createContext, useContext, useState, useEffect } from "react";
export ...
0
votes
1
answer
92
views
context resets to the initial value in the production environment
Description
I encountered a problem while using the Next.js App Router (version 14.2.6).
The issue occurs only in the production environment. it works perfectly fine in the local environment.
I'm ...
0
votes
0
answers
86
views
Electron-Vite-React - Persistent context accross routes
I have an Electron-Vite React (TSX) application. I am pretty new to coding Electron-Vite-React; perhaps my problem is because I am not understanding all the subtilities of certains concepts...
I have ...
0
votes
1
answer
54
views
React useContext(): Objects are not valid as a React child when trying to execute function in useContext() api to fetch data
I want to fetch the data by running the API in the useContext() api, basically this API gives me the number of items added in the cart and I need that number only which Im using it in Cart.js ...
-3
votes
1
answer
52
views
Why do I need a fancy jsx syntax for React Contexts [closed]
I've been out of the frontend js scene for a while, and now try to catch up on React etc.
I don't really get contexts. First you need to create a context somewhere, then you can use <Context....
1
vote
1
answer
35
views
Why attendence Context fetching again on navigation back to the teacherattend component?
I need to use attendance data often on my website, So I make it as utility as below:
import React, {
useState,
useEffect,
useMemo,
useCallback,
createContext
} from 'react';
import { ...
2
votes
2
answers
78
views
Context Provider not passing value to children
I am trying to create a parent/overarching context. The purpose of the context is to store UserInfo which should then be available to all children.
UserInfo is set by getting config from an API.
...
3
votes
0
answers
445
views
How to resolve hydration issue in Nextjs 15 with useOptimistic in my context utilizing React 19?
Playing with a store in Next.js 15 and using React 19 I'm running into an issue with my cart context and keep receiving a hydration error of:
An optimistic state update occurred outside a transition ...
-1
votes
1
answer
45
views
React Context provider with TypeScript Error
I'm trying to write and context to set an id in local storage . Here's my code
import React, {
createContext,
useEffect,
useMemo,
useState,
ReactNode,
} from 'react';
// Interface pour le ...
0
votes
4
answers
102
views
Is there any way to initialize a context with data from an api?
I'm trying to create a context whose default value will come from an external source. I would need to do something similar to doing the fetch outside of an asynchronous function (I don't think this is ...
1
vote
2
answers
158
views
How to implement 'useContext' in Next JS with .tsx files?
I am trying to implement dual theme (dark & light) in Next JS using MUI using use context method.
It gives me this error:
⨯ src\app\page.tsx (6:50) @ useThemeContext
⨯ TypeError: (0 , ...