Questions tagged [createcontext]

46 questions
6
votes
2 answers

useState with useContext in Typescript

Lets say I have a basic setup for checking whether a user is logged in or not: import { createContext } from "react"; const UserContext = createContext(null) export default UserContext In my App.tsx I want to create a useState hook…
jmsapps
  • 388
  • 2
  • 17
5
votes
2 answers

Conditionally execute useContext in React

I am looking to conditionally call useContext. This is my original code, which runs correctly, but fails tslint. Component that calls useResourceScope - say Component1 import { useEffect } from 'react'; export function useSubscribeListItemStore( …
3
votes
2 answers

What are the right types for a useContext with TypeScript/ReactJS?

I am refactoring to TypeScript a tutorial in ReactJS that I am following. For the most part, the tutorial teaches you how to refactor most of the code as bonus material. However the log-in part is done in ReactJS/JavaScript only and I tried to…
SrAlch
  • 33
  • 2
  • 5
2
votes
2 answers

dispatch with UseReducer and useContext hooks: dispatch does not exist on type {}

I'm trying to build a small Cesium app with React that can zoom to various places on the globe by clicking a button associated with each location. I'm working on setting up the reducer using the useContext and useReducer hooks, but I'm having an…
1
vote
2 answers

Uncaught TypeError: Cannot read properties of undefined (reading 'reduce')

I am trying to update a counter with clicking on a add button so I am passing the data though cart context and reading it to update my counter but the app is keep giving me the undefined error for "reduce" so this is the code: const HeaderCartButton…
1
vote
0 answers

AuthContext.Provider (AuthProvider) is rendering a blank page. I am using react version 18.2.0 and react-router-dom version 5.2.0

I was getting the output as expected until I started using the AuthContext here. But after that it just staring rendering a blank page. Can someone please help me out? Please take a look at my files Header.js: import React, {useContext} from…
1
vote
2 answers

How should fix createContext error in Typescript (React TS Auth with Contexts)

How should I fix the problem with createContext? It expects some arguments, but I can't see what arguments. I tried giving it some dummy currentUser: undefined variables and it kinda works, but I can't figure out what should I do with other…
1
vote
1 answer

createContext took default value instead of passed value

I'm creating a context that allows child components to setTheme. But the context when imported and used by useContext returned the default value instead of the passed value. How do I fix this? What this I do wrong? What is going on? Bad English,…
Fukumi
  • 13
  • 2
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
0 answers

React Calling function from other function, doesn't get the latest state value

I have a reducer to manipulate the Tableprops such as pagination, order, and filter. The TableProps will always updated everytime the is a change inside the table and its work fine. But when I call the delete function and then I call fetch function.…
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

Type 'never[]' is not assignable to type 'never'. TS2322 in passing to the value of ContextProvider using createContext Hook

I am not being able to assign the state and setState to the value parameter of ContextProvider Code:- import React, { useState, createContext } from 'react'; import { makeStyles } from '@material-ui/core'; import ProductHeader from…
1
vote
0 answers

Uncaught TypeError: _react.default.createContext is not a function. I have latest version of react and react-redux

I am trying to upgrade the application and using following versions for react and react-redux but getting this error."Uncaught TypeError:_react.default.createContext is not a function". The solution I have found so far is asking to update react and…
Diksha
  • 19
  • 3
1
vote
0 answers

Passing data from child component to parent component using contextApi, is that possible?

I am studying context hooks and everywhere I go, I see data being passed from parent to child components but I need it the other way around. Also, there are a few inputs on class based components but since i have no idea of class based components i…
0
votes
0 answers

Cannot share values between components using state context in react.js

I have a react.js application, that has multiple pages. I tried implementing the state context idea, but somehow I cannot get the value from useState in another component other than were I set the value. I tried two approaches, both of them don't…
1
2 3 4