Questions tagged [createcontext]

46 questions
0
votes
1 answer

console error :Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data') at handleClick

In this page the user can login, but if the untilDate is bigger than the current date it should log out the user. The code runs fine 1/2 times, the other giving me the error on the title. I am working with createContext for user login. This is the…
Mega Animenia
  • 15
  • 1
  • 6
0
votes
1 answer

React createContext with defult value for use Mobx store

i am creating a context to use Mobx store in my React application, by following the example: const mainStore = new MainStore(); // mobx store instance const storeContext = React.createContext(mainStore); export const useStores = () =>…
0
votes
0 answers

React Hooks - custom useAuth hook does not work as expected

I am new to react and am experimenting a bit. I have a bit of code and I am not sure why it is not working. I tried to implement an own hook & context to provide user authentication data along my application. The main parts pf the coding are as…
MyUser
  • 1
  • 1
0
votes
1 answer

Why does useContext need the if statement when I use typescript?

It's just a simple createContext and useContext code. I struggled a lot until I realised that an if statement is necessary in the useTodoContext function. When I comment out the if statement line, then I get an error. Can you tell me doesn't work…
venndi
  • 161
  • 9
0
votes
1 answer

how to use useEffect and useContext with fetching data?

I'm trying to use React's Context API as well as Hooks with fetching data. I'm coding [createContext] like below, but it doesn't work. import { createContext, useEffect } from "react"; export const ColorContext = createContext({}); export const…
Yuzu
  • 59
  • 1
  • 8
0
votes
1 answer

React createContext running mutation function not working correctly

I am having a problem i can't seem to understand why is happening since i have the same example working in codesandbox, but in my app it shows a different behavior. In my app i can see the context from the consumer both the bool and the function,…
Holmar K
  • 100
  • 1
  • 8
0
votes
1 answer

Reactjs update context from children component

Starting with ReactJS and NextJS I have the following Layout component and using context to set values from the children component export interface AuthContextModel { title: string; description: string; showSignup: boolean; } export…
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
0
votes
2 answers

React.useContext appearing as undefined

This is my first time using the React context hooks in an app and my context default value keeps appearing as "undefined." Troubleshooting so far: I've made sure React.createContext is in a separate file (context.js) I've made sure the child…
0
votes
0 answers

React Native - How to update a value for entire application

What is the best way to find a value in the api request and make it available in the entire application? I need to get the total of unread messages and show it to the user in the application header. Every time you change pages, a new request is made…
0
votes
1 answer

Why useReducer doesn't update state in React context

I'm using useReducer and context to update my state in App.js then send data to the database but it doesn't update the state and always is null. App.js import AuthContext from './context'; import screenA from './screenA'; export default function…
Ali Mahmoudi
  • 83
  • 2
  • 8
0
votes
1 answer

problem call `useContext` then my other `state` set to default value

in my code i used one context for saving data and one state for get active id . my problem is when i setState and then setContext , when i get state value i see state set default value ! export default function AddKnowledgeScreen({ route,…
0
votes
4 answers

How to pass a value using `createContext` from parent to child's child component?

Instead of passing props from parent to child1(parent of child2) ->to child2, I want to use createContext and receive the value with useContext. What I tried to do is not correct because and I'm getting an error **'booleanContext' is not…
ExtraSun
  • 528
  • 2
  • 11
  • 31
0
votes
1 answer

Error importing context with React native

I'm learning to use context with React native, actually i'm following a blog where define how use createContext and useContext for Authentication logic in any app with React and Navigation. In the blog not define how to import the class AuthService…
Dr oscar
  • 359
  • 1
  • 4
  • 16
0
votes
1 answer

Issue with state update approach for nested objects

Major EDIT I have quite huge object which is 3 level deep. I use it as a template to generate components on the page and to store the values which later are utilized, eg: obj = { "group": { "subgroup1": { "value": { "type":…
0
votes
1 answer

Import store using createContex mobximport store as props createContext mobx

there is a class that unites all classes of the store. You need to pass this class to app.js so that you can get it in any of the files using createContext