Questions tagged [use-context]

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

586 questions
0
votes
0 answers

How to solve customHooks call signature error in react with typescript

I am new in typescript. I tried to solve call signature error but I couldn't figure it out. I try to use custom hooks which it takes a context props and then return the contex like below export const useCardContext = (): ContextProps => { const…
0
votes
2 answers

React useContext is returning undefine

I am just getting started with react useContext and have run into a problem i could not find solution. When the context created is called in another file it returns undefined. I have tried to research multiple answers like this and others but could…
e.iluf
  • 1,389
  • 5
  • 27
  • 69
0
votes
1 answer

React Native : undefined is not an object (evaluating '_useContext.width')

I want to create a reusable code for different screen sizes. I'm using createContext API so that I wont get to rewrite the code in different screen. I got this error null is not an object (evaluating '_useContext.width) Btw, I'm using the…
amrxlamn
  • 3
  • 4
0
votes
0 answers

TypeError: Cannot read property 'find' of undefined trying to add extra items to Cart

I am trying to add extra items to the Cart using useContext, but the code keeps crashing with the error of "TypeError: Cannot read property 'find' of undefined". I want to add the items in the Cart and I do not know if this code should work, perhaps…
Joaquin Palacios
  • 287
  • 8
  • 33
0
votes
1 answer

nextjs - useContext Cannot destructure property 'user' of 'Object(…)(…)' as it is null

I'm getting an error when I try to use useContext with next.js Here I create the context: import React, { createContext } from 'react'; const FirebaseContext = createContext(null); export default FirebaseContext; This is my index…
dylan1496
  • 1
  • 1
0
votes
1 answer

Preventing state item in all components from changing with useContext()?

I'm trying to control the state of 2 components use useContext() in React-Native. I have a flatmap of cards that render on a screen. Each card has a press-able 'interested' icon. If I click on a card, it shows the details of the card and also the…
Demian Sims
  • 871
  • 1
  • 14
  • 29
0
votes
1 answer

Carry Page context/state across components using react hooks

I am new to react hooks. We are developing a react based application without redux. We have a single page where we have different components like search, filters, grid, pagination etc. Whenever we does any action on page , Grid should get refreshed…
0
votes
2 answers

React - problem using useContext & useReducer

Hey I had a problem while using useContext (React Hooks) and useReducer (for store a array with 4 values of string). Explained in the pictures down below what exactly it's wrong and what I have done. Thank u App.js - using ItemsByCategory (Line 7).…
0
votes
1 answer

Transferring data from one state object to another while using React context in a Next.js app

I'm building a pretty simple restaurant website using React and Next.js. I have a home page and an 'order' page, which renders a menu from a state object ('menuitems'). I want the user to be able to add items to their 'cart', which is another state…
0
votes
1 answer

Combine useMachine with useContext

I'm working on a UI project which handles state updates through a shared context, very similar as described here const {appState, dispatch} = useContext(AppContext); I'm not toying around with state machines through xstate for some of the…
Bogey
  • 4,926
  • 4
  • 32
  • 57
0
votes
2 answers

Trying to connect using FacebookAuthProvider from Firebase but get error. react native

I'm trying to connect new users through Facebook authentication and Firebase SDK with createContext, but I'm getting: new FacebookAuthProvider() is not supported on the native Firebase SDKs. I'm using the firebase doc here :…
0
votes
2 answers

Why I am getting a Typescript error while using useContext with React?

I am creating a Context using useContext with TypeScript. I have a function into seperate file MovieDetailProvider.tsx as wrapper in my App.tsx file. import { Context, MovieObject } from '../interfaces/interfaces' export const MovieDetailContext =…
0
votes
1 answer

React Hooks: useEffect, useReducer, createContext and localStorage; TypeError: Cannot read property of undefined

I am using local storage in my Map app for some persistent storage; also using React.createContext coupled with useReducer to share and update state amongst components. State in local storage, and in the app when consoled are updating and present,…
0
votes
1 answer

Form values not getting updated in context api React

I'm trying to update the UserContext through form inputs but the value of the context remains null and doesn't shows the Logout button. setUser doesn't change username and password values, it's initialized to null only. But if I remove the form part…
minsuga
  • 321
  • 3
  • 11
0
votes
1 answer

useContext returns undefined in _app.js (Next.js)

Using Next.js, I can get the context value in header.js file without a problem but it returns undefined in _app.js Here is my code. useLang.js import { createContext, useContext, useState } from 'react' const LangContext = createContext() export…
bubbleChaser
  • 755
  • 1
  • 8
  • 21