我试图在从子组件改变状态后更新状态并且没有成功,每次我调用函数时我得到堆栈溢出,prop都调用无限次函数,但问题是,我真的需要更新这种状态,目前还不知道如何解决这个问题.
亲
import React, { PropTypes, Component } from 'react';
import Card from './card/card.js';
import style from './style.scss';
class Container extends Component {
constructor(props) {
super(props);
this.state = {
isFlipped: false,
oneOpened: true,
history: [],
childFlipToFalse: false,
};
this.historyToggleStates = this.historyToggleStates.bind(this);
this.forceFlipParent = this.forceFlipParent.bind(this);
this.checkForceFlip = false;
}
historyToggleStates(bool, id, callForceFlip) {
this.setState({
history: this.state.history.concat([{ opened: bool, id }]),
}, () => {
console.log('inside historyToggleStates');
if (callForceFlip) {
this.forceFlipParent()
}
});
}
forceFlipParent() {
const { history } = this.state; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用来自用户的 GraphQL API 数据的查询来检查我的用户是否已登录,如果它已登录,则应返回未定义或某些错误。
问题是我有一个 func 调用removeSession,当用户单击注销按钮时,它会从我的 localStorage 中删除令牌。问题现在开始,我意识到我的令牌已从 localStorage 中清除,但之后没有触发 userLAzyQuery。所以为了检查我开始手动删除 de token 并且在 onClick 之后我调用了sendQuery()
为了强制我的检查,我在查询后创建onCompleted和onError回调,你猜怎么着?也没有被调用。
头文件.js
import { Fragment, useEffect } from 'react';
import Link from 'next/link';
import { isAuthenticatedQuery } from '../queries';
import { useQuery, useLazyQuery } from '@apollo/react-hooks';
import Router from 'next/router';
function isActive(pathname) {
return typeof document !== 'undefined' && document.location.pathname === pathname;
}
const Header = () => {
const { loading, data: dataAuth, error } …Run Code Online (Sandbox Code Playgroud)