react-context

Apollo Client Cache vs. Redux

自作多情 提交于 2020-08-19 06:05:29
问题 I'm trying to migrate from Redux Store to use Apollo Client Cache that comes with Apollo Graphql Client. One of the key features that sets Apollo Client apart from other data management solutions is its normalized cache . Just by setting up Apollo Client, you get an intelligent cache out of the box with no additional configuration required. With Redux we have to write actions, types and dispatch actions based on the response received from the side-effect and set the data in the store using

Cancel all subscriptions in a useEffect cleanup function created by Context.Consumer

和自甴很熟 提交于 2020-08-10 21:33:04
问题 Each time when onClick executes I received a warning message about memory leak. How component can be can unsubscribed from the Context.Consumer in my functional component with useEffect hook? I did not find a way how to unsubscribe from the AppContext. AppContext.unsubsribe() did not work. import React, {useState, useContext} from 'react'; import {withRouter} from 'react-router-dom'; import axios from 'axios'; import {AppContext} from "../context/AppContext"; const LoginPage = (props) => {

Cancel all subscriptions in a useEffect cleanup function created by Context.Consumer

北城余情 提交于 2020-08-10 21:33:03
问题 Each time when onClick executes I received a warning message about memory leak. How component can be can unsubscribed from the Context.Consumer in my functional component with useEffect hook? I did not find a way how to unsubscribe from the AppContext. AppContext.unsubsribe() did not work. import React, {useState, useContext} from 'react'; import {withRouter} from 'react-router-dom'; import axios from 'axios'; import {AppContext} from "../context/AppContext"; const LoginPage = (props) => {

Is it a misuse of context to use it to store JSX components for display elsewhere?

陌路散爱 提交于 2020-08-07 05:49:57
问题 I have an application where users will click various parts of the application and this will display some kind of configuration options in a drawer to the right. The solution I've got for this is to have whatever content that is to displayed, to be stored in context. That way the drawer just needs to retrieve its content from context, and whatever parts of that need to set the content, can set it directly via context. Here's a CodeSandbox demonstrating this. Key code snippets: const

Is it a misuse of context to use it to store JSX components for display elsewhere?

柔情痞子 提交于 2020-08-07 05:49:50
问题 I have an application where users will click various parts of the application and this will display some kind of configuration options in a drawer to the right. The solution I've got for this is to have whatever content that is to displayed, to be stored in context. That way the drawer just needs to retrieve its content from context, and whatever parts of that need to set the content, can set it directly via context. Here's a CodeSandbox demonstrating this. Key code snippets: const

Too many React Context providers

£可爱£侵袭症+ 提交于 2020-07-31 07:34:49
问题 New to react here and trying to wrap my head round the new Context API (I haven't looked into Redux etc. yet). Seems I can do much of what I need to do, but I'm going to end up with lots and lots of providers, all needing a tag to wrap my main app. I'm going to have a provider for Auth, one for theming, one for chat messages (vis Pusher.com) etc. Also using React Router is another wrapper element. Am I going to have to end up with this (and many more).... <BrowserRouter> <AuthProvider>

Too many React Context providers

天涯浪子 提交于 2020-07-31 07:31:52
问题 New to react here and trying to wrap my head round the new Context API (I haven't looked into Redux etc. yet). Seems I can do much of what I need to do, but I'm going to end up with lots and lots of providers, all needing a tag to wrap my main app. I'm going to have a provider for Auth, one for theming, one for chat messages (vis Pusher.com) etc. Also using React Router is another wrapper element. Am I going to have to end up with this (and many more).... <BrowserRouter> <AuthProvider>

Difference Between Class.contextType and Context.Consumer with working example

*爱你&永不变心* 提交于 2020-07-10 03:15:24
问题 I am trying to understand the React context API and was going through the official docs. I will appreciate if someone can throw some more light on the following points as the official doc does not address it clearly. What is the difference in contextType and Consumer methods to consume the values provided by Provider? In what situation we should use which method? Can the value exposed by Provider in a class based component, be used by a react hook component using useContext? I had the same

Accessing consumed React.Context in Next.js getInitialProps using HOC

我们两清 提交于 2020-06-24 14:42:05
问题 I am attempting to abstract my API calls by using a simple service that provides a very simple method, which is just an HTTP call. I store this implementation in a React Context, and use its provider inside my _app.js , so that the API is globally available, but I have a problem at actually consuming the context in my pages. pages/_app.js import React from 'react' import App, { Container } from 'next/app' import ApiProvider from '../Providers/ApiProvider'; import getConfig from 'next/config'

React Authentication Context being null initially

时光总嘲笑我的痴心妄想 提交于 2020-06-17 06:22:50
问题 I'm using React contexts in order to hold my authentication state for my application. Currently, I'm having an issue where whenever I try and hit /groups/:id , it always redirects me to /login first and then to /UserDash . This is happening because the context of my AuthProvider isn't updating fast enough, and my Private Route utilized the AuthContext to decide whether to redirect or not. <AuthProvider> <Router> <Switch> <LoggedRoute exact path = "/" component = {Home}/> <Route exact path = "