Questions tagged [createcontext]

46 questions
0
votes
1 answer

How to call setExpenses() after every updateExpense() call

The problem is that the expenses array is not being updated after submitting the updated expense and that is what's providing expenses throughout the app. In order to reflect the updates I have to reload the app (so the useEffect hook can set the…
codereyes
  • 47
  • 9
0
votes
0 answers

Can not call await/async function in useContext with Nextjs 13

I have this simple PostContext in nextjs 13 'use client' const PostsContext = createContext(undefined); export function PostsProvider({ children }: { children: ReactNode }) { const [posts, setPosts] =…
0
votes
1 answer

react createContext: date.toISOString is not a function

When I call on getFormattedDate: export function getFormattedDate(date) { // return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate() +1}` return date.toISOString().slice(0, 10) } In this line:
codereyes
  • 47
  • 9
0
votes
1 answer

UseContexts and Createcontex in React

I was trying to use React's context and I faced the following issues. I am new to react, so bear with me and would appreciate if you can direct me to a useful resource Does a component has to be wrapped inside of a provider to be able to access the…
0
votes
2 answers

Use of context API

I have tried multiple ways. Watched many solutions above but still couldn't solve this issue. Can anyone please help me using context in my project. SearchContext.jsx import { createContext } from 'react'; const SearchContext =…
0
votes
0 answers

Create Context issue

I have a Search.jsx file where I take the username as input from the user. I want to pass the username to the rest of my project, so I decided to use a context. However, I am encountering an issue where I'm getting an undefined value when I try to…
0
votes
0 answers

React Native - createContext + useContext returning undefined

I have a file named AuthProvider.js which holds the processing functions within a context as follows: import React, { createContext, useState } from 'react'; import auth from '@react-native-firebase/auth'; export const AuthContext =…
0
votes
0 answers

What really should you pass into createContect()?

I see all of the following forms: createContext() createContext(null) createContext({}) createContext(theme: 'light', toggleTheme: () => {}) example of #4 is here. So can you just use #1 or #2 above and they are the same as #3 or #4? #4 above…
Stefanie Gauss
  • 425
  • 3
  • 9
0
votes
1 answer

How to make an empty createcontext in typescript?

I keep wanting to use a use cotext hook but i learned to use use context by putting an empty {} in the create context thing. But it is giving me errors. Not assignable to {} and type any not available. import React from "react"; type data = { …
user19538316
0
votes
2 answers

createContext undefined

When I try to use createContext() the console gives me this error: App.js:6 Uncaught TypeError: Cannot destructure property 'consoleLogFunction' of '(0 , react__WEBPACK_IMPORTED_MODULE_1__.useContext)(...)' as it is null. I've seen others asking…
jeansvf
  • 13
  • 5
0
votes
0 answers

Logic behind using nested useContext provider

I was learning about useContext and I get confused and can't really picture a use case for nested providers... Here is an example from React's documentation: // Theme context, default to light theme const ThemeContext =…
0
votes
2 answers

React useContext getting undefined

there is a simple codesandbox example [https://codesandbox.io/s/red-butterfly-kz13ee?file=/src/userName.jsx:0-270][1] I have two components first one is a surname and the second one is a username where I have a greeting and trying to import the last…
Dave
  • 3
  • 3
0
votes
1 answer

How to use useReducer with createContext?

I am learning how to create a React reducer to be used in a React context. Can someone explain why the instructor created the {currentUser: null} object twice? Once in the context (line 7), once as an INITIAL_STATE to be used in the reducer (lines…
chu-js
  • 181
  • 7
0
votes
0 answers

Why when updating useContext it doesnt update in other pages React Native

I have created useContext and want to update it in one tab screen and recieve it in others tab screens. I created Context file import React, { createContext } from "react"; export const ChampContext = React.createContext('test'); In Home screen Im…
0
votes
2 answers

TypeScript on useContext

I'm following a React tutorial on youtube where I'm trying to convert the Project from JavaScript to TypeScript, and I'm having a lot of trouble with the useContext, I would appreciate it if someone were to help me here. If you're wondering which…
Bardyli
  • 45
  • 4