react-context

Cannot read property 'history' of undefined (useHistory hook of React Router 5)

让人想犯罪 __ 提交于 2020-05-28 12:03:04
问题 I am using the new useHistory hook of React Router, which came out a few weeks ago. My React-router version is 5.1.2. My React is at version 16.10.1. You can find my code at the bottom. Yet when I import the new useHistory from react-router, I get this error: Uncaught TypeError: Cannot read property 'history' of undefined which is caused by this line in React-router function useHistory() { if (process.env.NODE_ENV !== "production") { !(typeof useContext === "function") ? process.env.NODE_ENV

Unit testing: react context api with enzyme return an empty object

若如初见. 提交于 2020-05-23 09:52:29
问题 I am trying for the first time to use React context API to pass information from a main component to his grandchild component. So first I have created a context Here is the main component that define the context The parent component don't care about the context and is just here to create the grand child component And here is the child component that reads the context So far no problem. Everything works as expected. The ChildComponent have retrieve the context value. The problem comes when I

React Context API not working from custom NPM component library

白昼怎懂夜的黑 提交于 2020-03-18 12:47:21
问题 I've built a ReactJS component library that I use for multiple projects installed via an NPM package using a sim link. I want to use the context API to pass data from a parent component served from the component library to my base project to be consumed by multiple consumer components also served from the component library. When I try the context is always undefined in my child components. If I place my consumer component in my provider component within my library it works like a champ but

React createContext issue in Typescript?

好久不见. 提交于 2020-02-27 04:45:07
问题 So I'm having a very weird issue with React Context + Typescript. Working example In the above example, you can see what I'm trying to do actually work. Essentially I'm managing state with the new useContext method, and it works perfectly. However, when I try to do this on my box, it cannot seem to find the state values being passed through the useReducer. export function AdminStoreProvider(props: any) { const [state, dispatch] = useReducer(reducer, initialState); // state.isAuth is avail

Remove Zoom control from map in react-leaflet

限于喜欢 提交于 2020-02-06 08:43:09
问题 I am building a react-leaflet application, and I am trying to separate the zoom control from the map itself. The same question in a vanilla Leaflet context was asked here: Placing controls outside map container with Leaflet?. This is what I'm trying to accomplish within the react-leaflet framework. Here is the general outline of my project: import UIWindow from './UIWindow' import Map from './MapRL' class App extends React.Component { render () { return ( <div className="App"> <Map />

Remove Zoom control from map in react-leaflet

北战南征 提交于 2020-02-06 08:43:04
问题 I am building a react-leaflet application, and I am trying to separate the zoom control from the map itself. The same question in a vanilla Leaflet context was asked here: Placing controls outside map container with Leaflet?. This is what I'm trying to accomplish within the react-leaflet framework. Here is the general outline of my project: import UIWindow from './UIWindow' import Map from './MapRL' class App extends React.Component { render () { return ( <div className="App"> <Map />

React Context api - Consumer Does Not re-render after context changed

陌路散爱 提交于 2020-01-23 07:49:50
问题 I searched for an answer but could not find any, so I am asking here, I have a consumer that updates the context, and another consumer that should display the context. I am using react with typescript(16.3) The Context(AppContext.tsx): export interface AppContext { jsonTransactions: WithdrawTransactionsElement | null; setJsonTran(jsonTransactions: WithdrawTransactionsElement | null): void; } export const appContextInitialState : AppContext = { jsonTransactions: null, setJsonTran : (data:

React Context api - Consumer Does Not re-render after context changed

試著忘記壹切 提交于 2020-01-23 07:49:50
问题 I searched for an answer but could not find any, so I am asking here, I have a consumer that updates the context, and another consumer that should display the context. I am using react with typescript(16.3) The Context(AppContext.tsx): export interface AppContext { jsonTransactions: WithdrawTransactionsElement | null; setJsonTran(jsonTransactions: WithdrawTransactionsElement | null): void; } export const appContextInitialState : AppContext = { jsonTransactions: null, setJsonTran : (data:

React Context api - Consumer Does Not re-render after context changed

自古美人都是妖i 提交于 2020-01-23 07:49:10
问题 I searched for an answer but could not find any, so I am asking here, I have a consumer that updates the context, and another consumer that should display the context. I am using react with typescript(16.3) The Context(AppContext.tsx): export interface AppContext { jsonTransactions: WithdrawTransactionsElement | null; setJsonTran(jsonTransactions: WithdrawTransactionsElement | null): void; } export const appContextInitialState : AppContext = { jsonTransactions: null, setJsonTran : (data:

Function passed as parameter takes old store from React Context API

我怕爱的太早我们不能终老 提交于 2020-01-16 09:05:13
问题 When I get 401 status code from backend I run refreshToken method with passing the function where expired token occurred. In refreshToken method I get new token and set in refreshTokenLastFunc property function from parameter. Then I watch when refreshTokenLastFunc was updated using React useEffect and run once again the function where expired token occurred. The problem is while I run store.refreshTokenLastFunc() in useEffect, the function in refreshTokenLastFunc property uses old Context