当前位置: 首页 > 知识库问答 >
问题:

rangeerror axios GET请求中超出了最大调用堆栈大小

闻人冷勋
2023-03-14

我有非常简单的组件与axios和材料表。axios请求中的数据应该只加载一次,然后单击刷新按钮。

import React, { useState, useEffect } from 'react';
import { withStyles } from '@material-ui/core/styles';
import { FormattedMessage, injectIntl } from 'react-intl';
import { Typography, Paper } from '@material-ui/core';
import MaterialTable from 'material-table';
import axios from 'axios';
import { appConfig } from '../../../config';

import drawerStyle from '../../../styles/drawers';

const styles = (theme) => ({
  drawerPaper: drawerStyle(theme).drawerSmall,
});

const components = {
  Container: ({ children }) => {
    return <Paper elevation={0}>{children}</Paper>;
  }
};

const DemoRequests = (props) => {
  const { intl } = props;
  const [requests, setRequests] = useState([]);

  const url = `${appConfig.URL_REST}administration/demo_registration_request`;

  const config = {
    headers: { Authorization: `Bearer ${localStorage.getItem('token')}` },
  };

  const fetchRequests = () => {
    axios.get(url, config)
    .then((res) => {
      //setRequests(res.data.demoRequests);
      console.log(res);
    })
    //.catch(error => console.log(`Error: ${error}`));
  };

  useEffect(() => {
    fetchRequests();
  }, []);

  return (
    <>
      <MaterialTable
        title={
          <Typography variant="h5" component="span">
            <FormattedMessage id="administration.demoRequests.table.title" />
          </Typography>
        }
        columns={[
          {
            title: <FormattedMessage id="administration.demoRequests.table.id" />,
            field: 'id',
          },
          {
            title: <FormattedMessage id="administration.demoRequests.table.company" />,
            field: 'company',
          },
          {
            title: <FormattedMessage id="administration.demoRequests.table.email" />,
            field: 'email',
          }
        ]}
        data={requests}
        //components={components}
        options={{
          padding: 'dense',
          searchFieldStyle: { margin: '40px' },
          rowStyle: { fontSize: '0.8125rem', padding: '0px' },
          cellStyle: {
            padding: '2px 16px 1px 16px',
            maxHeight: '36px',
          },
        }}
        actions={[
          {
            icon: 'refresh',
           tooltip: intl.formatMessage({ 
             id: 'administration.demoRequests.table.tooltip.refresh.data' 
           }),
            isFreeAction: true,
            onClick: () => fetchRequests(),
          }
        ]}
      />
    </>
  );
}
    
    export default injectIntl(
  withStyles(styles, { withTheme: true })(DemoRequests)
);

取消注释设置请求(res.data.demo请求)给我堆栈大小超过了错误,但我在这里看不到错误。我到底做错了什么?

编辑:尝试重新安装npm,将状态添加到useffectdependency数组,获取useffect

共有1个答案

焦正德
2023-03-14

解决方案是在Chrome浏览器上安装React Developer Tools扩展

 类似资料:
  • 我正在使用我岳父让我建立的一个网站作为学习React的借口。我不是一个天生的JavaScript开发人员(更喜欢后端),我知道我下面的代码中可能有一些递归元素,但我就是看不到。谁能告诉我我做错了什么?

  • 我正在尝试将文档批量插入MongoDB(因此绕过Mongoose并使用本机驱动程序,因为Mongoose不支持批量插入文档数组)。我这样做的原因是为了提高写作速度。 我收到错误RangeError: Maximum Call Stack Size Exceeded在console.log(err)在下面的代码: 类似于:https://stackoverflow.com/questions/243

  • 问题内容: 我有一台服务器,可能导致以下输出死亡: 但是,如果没有堆栈转储或跟踪,就无法确定这是无限递归还是只是链太大而已,更不用说问题函数在哪里了。 使用该选项运行Node 不仅使我的测试运行缓慢(正如人们期望的那样),而且没有重现该问题。 有人有任何解决方案或提示来深入了解此问题吗? 问题答案: 看来目前的答案是:站稳脚步,等待Node.js更新到新的V8版本,或者使用此Chromium项目错

  • 问题内容: 当我运行我的代码时,Node.js引发由过多的递归调用引起的异常。我试图将Node.js堆栈大小增加,但是Node.js崩溃而没有任何错误消息。当我不使用sudo再次运行此命令时,Node.js将输出。是否有可能在不删除递归调用的情况下解决此问题? 问题答案: 您应该将递归函数调用包装到 , 要么 函数使node.js有机会清除堆栈。如果您不这样做,并且有很多循环没有任何 真正的 异步

  • 问题内容: 我想这意味着有一个循环引用,但是对于我的一生,我无法猜测如何解决它。 有人有主意吗? http://plnkr.co/edit/aNcBcU?p=预览 检查Chrome中的调试控制台(例如),您将看到错误。冒犯的行是 通过以下方式在控制器上对scope.map进行“ $ watched” 问题答案: 这是因为您要比较对象是否相等,而不是参考。将您的声明更改为此:

  • 如果用户未登录,我尝试将用户重定向到“TrapPage”。 这是我的代码: 当我将函数requireAuth放在onEnter上时,控制台给我一个错误: 我是一个反应迟钝的人,请耐心点:) 我的代码有什么问题?