我正在尝试使用React创建一个简单的ToDo应用程序,下面是我的app.js文件:
import React from 'react';
import { render } from 'react-dom'
import ToDoList from './toDoList'
import CreateToDos from './createToDos'
import _ from 'lodash'
let toDos = [
{
task: 'task 1',
api-service.js代码
import CustomToaster from "../toaster/toaster";
export async function saveData(){
return new Promise(async(resolve)=>{
try {
let res=await fetch('http://localhost:5000/test',{
//mode: 'no-cors'
heade
这似乎是一个常见的问题,但我尝试过几种配置,并且一直得到错误消息Warning: Can't call setState on a component that is not yet mounted。我在我的应用程序的其他组件中以类似的方式使用setState(),没有问题,所以我不知道为什么我的App组件认为我试图在构造函数中调用setState(),而它显然不在构造函数之外。
这是我尝试使用componentDidMount()生命周期方法的尝试。显然,在这方面我完全缺少一些东西,但是我无法收集到很多关于setState()的文档。特别是考虑到我在我的应用程序的其他部分中使用了这种
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Clock component.
为什么要显示此错误??当我从我的应用程序注销时,这个警告开始出现在控制台上。有人能解释一下为什么会这样吗?
const Clock = React.createClass({
ge
警告:
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the _class component.
知道它从哪里来的吗。抓到什么了吗?
我已经查看了代码中的所有setState,并对它们进行了替换以确保。找不到它的来源..。
到目前为止,我的观察是:
只有在我的测试中才会发生
在我的测试中有以下警告:
Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.
Please check the code for the ProtectedRoute component.
所以我检查了我的ProtectedRoute组件。此组件构建于react-router的Route组件之上,并在呈现路
当尝试单击delete按钮时,将显示错误,声明无法读取null的属性,并尝试使用bind.this绑定构造函数类中的方法,但再次显示相同的错误。还绑定了组件底部的值,同样的错误无法将属性的值读取为空
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import SampleData from './data.js';
import _ from
我正在开发一个非常简单的应用程序,我得到了这个以前没有见过的错误,之前的线程也没有为我解决。我的代码如下,请注意我的应用程序根本没有完成,我只是不确定为什么我会得到这个错误。我最好的猜测是我初始化状态是错误的,但我已经更改了一些项,但都没有用:
WIP code:
import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import axios from 'axios';
const api = ax
在写康威的“生命游戏”的时候,我遇到了一个错误,在这个错误中,状态实际上并没有被更新。我得到了一个警告,setState(...): Can only update a mounted or mounting component.,但到目前为止,我试图摆脱它的一切都没有帮助。您可以在下面找到我的应用程序组件:
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
board: [],
rows: 50,
cols: