我无法解决此问题,该如何解决?
import React, { Component } from "react";
import "./Main.css";
import { FaSearch, FaEdit, FaWindowClose } from "react-icons/fa";
export default class Main extends Component {
state = {
pesquisaNFE: "",
resultado: [],
};
handleSubmit = (e) => {
e.preventDefault();
const { resultado } = this.state;
let { pesquisaNFE } = this.state;
pesquisaNFE = pesquisaNFE.trim();
if (resultado.indexOf(pesquisaNFE) !== -1) return;
const newSearch = [...resultado];
this.state({
resultado: [...newSearch, pesquisaNFE],
});
};
错误:
答案 0 :(得分:4)
要更新状态,您需要致电this.setState
将this.state({
更改为this.setState({