Questions tagged [use-context]

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

586 questions
0
votes
1 answer

HOC with useContext. Invalid hook call. Hooks can only be called inside of the body of a function component

I am trying to write an HOC with MaterialUI's Snackbar to be able to show error in any network failure. Getting below error, can someone please help: react-dom.development.js:14724 Uncaught Error: Invalid hook call. Hooks can only be called inside…
Deepak Negi
  • 214
  • 4
  • 11
0
votes
1 answer

How to send array of objects data from child component to parent component and store in the parent object using react hooks?

This is my parent component js file... import React, { useContext, useState } from "react"; import TaskListContextProvider from "./TaskListContext"; import TaskList from "./TaskList"; import TaskForm from "./TaskForm"; const AddMenu = () => { …
0
votes
1 answer

Context object is empty when using useState object in NextJS

I am trying to pass a context object in NextJS which is using data from a useState hook, but the state variable and setState functions are undefined when consumed. This is strange since when I pass a simple variable in its place, it works fine, it…
FRMR
  • 289
  • 3
  • 27
0
votes
1 answer

slowness in react native application

I recently created an application with react native in which I use Axios to request addresses of images from a database, the problem arises that on the main screen I made the request and through a map, I render a list of images and when moving to…
laura
  • 1
0
votes
1 answer

How to access the context of a unknown parent

Suppose, I have two separate components X and Y, where X is a dependency in Y(not a direct child in the project). Is it possible to access the context of Y in X? ex: X is a separate project…
Benison
  • 157
  • 1
  • 2
  • 17
0
votes
1 answer

Storing Axios response in AppContext

I'm trying to build a section of my site that will dynamically pull in contact information from a REST API. At this point I'm using the sample API from https://jsonplaceholder.typicode.com. I'm trying to use axios, specifically the useAxios and…
Jesse Winton
  • 568
  • 10
  • 33
0
votes
2 answers

Is there a way to make context only re-render if its data changes?

As depicted below, I have a basic react context setup. My desire is child components consuming the context should only re-render when the context data changes, but I'm finding that's not the case. If I update call setData2, which is not associated…
temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
0
votes
1 answer

Uncaught TypeError: Object is not iterable when using useReducer with useContext for global store React js

I am trying to use hooks to replace the redux store with action and reducers I have created a global store using createContext and a global reducer using useReducer and trying to use the global state object with useContext in the below file which is…
0
votes
1 answer

Why is the onClick event triggering twice even though there's e.preventDefault using hooks in React?

Update: The problem is directly in the reducer and has nothing to do with the onClick function nor the deleteLastItem function. I tested this with console.logs and apparently the only one repeating twice is the one directly in the reducer. I was…
gxp2
  • 149
  • 2
  • 11
0
votes
1 answer

Why the React component update doesn't work

I wanted to understand react-redux and I have absolutely no idea why the components are not updated. I think nothing is updated because react doesn't look into the depth of context changes. But even with these thoughts I do not know what to do…
0
votes
1 answer

pass existing context to my setContext react hook (JS question)

My current context with a method to set the updated context looks like this: export const AppContextProvider = ({ children }) => { const [currentAppContext, setCurrentAppContext] = useState(initApp) const setAppContext = values => { …
Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
0
votes
2 answers

How to trigger a re-render in a component via useContext when said context is updated in another component

I am attempting to update a table with with the response from an API. The response comes to one component and the table lies in another. I can see that I am successfully updating the context in the component but it doesn't seem to pass to the…
J-Daniel-S
  • 47
  • 8
0
votes
0 answers

useEffect re rendering context api consumer component

I am trying to understand and practice React hooks. I have the following code with me. import React, { useState, useEffect, useReducer } from "react"; import "./App.css"; import DisplayUser from "./comp/DisplayUser"; const initialState = { …
0
votes
1 answer

TypeError: Object is not iterable when I using ContexAPI in Reactjs

I'm trying to share data between component using ContextAPI in ReactJs. But I have a stuck when using it. This err is : "TypeError: Object is not iterable (cannot read property Symbol(Symbol.iterator))" at line 7: *const [state, dispatch] =…
0
votes
2 answers

I need to update array state in React using useContext and map function

So I am working on a movie app for my friends and I. I have a previous post about a similar issue but I'm now having a different issue trying to update the state of my movieList with useContext and arrays Here is my useContext array structure: …