我从表单组件中获取数据,并试图用这些数据设置我的app组件的状态。
但是,state.data是一个空对象,不更新数据。在将模型数据设置为检查是否存在之前,我将对其进行控制台日志记录。它们是模型中的数据。
import React, { Component, Fragment } from "react";
import Form from "../components/Form";
import product from "./product.json";
class App extends Component {
constru
我有一个react组件,可以显示数据库中的所有书籍。然而,当我第一次点击这个按钮时,它不会列出所有的书,但是如果我再次点击这个按钮,它会列出所有的书,我怎么让它只点击一次就把所有的书都列出来了呢?
import PropTypes from "prop-types";
import {getBook} from "../actions/bookActions";
import {connect} from "react-redux";
import {Container} from "@material-ui/core";
imp
谁能告诉我,在我的主页组件上单击提交后,如何清除所有输入?我试着在subjectForm组件中使用了reset()方法,但是我不是用错了就是不起作用。我还尝试使用setState,并将我的输入恢复为默认状态,该状态为空,但同样不起作用。
我的代码中的所有内容都运行良好,但是每次我提交一个主题时,字段都不会自动清除
这是我的主页组件。
import React from 'react';
import SubjectForm from './SubjectForm';
import {addSubject} from '../act
I有一个应用程序组件和测试组件。i在应用程序和测试组件的呈现方法中都添加了console.log。我可以看到应用控制台只呈现一次,但是测试组件呈现了两次。也是,我在测试组件中有一个具有受控输入的表单,但一旦我开始键入输入字段,.The测试组件就会重新呈现两次。
app组件
import React from "react";
import "./styles.css";
import Test from "../Test";
export default function App() {
return (
<div class
我对下面的代码有一个问题: type Formdata{
title: string
cant: number
description
}
// I replace this code to the another code any[], but not
// resolving the problem
// const [sendData, SetsendData] = React.useState<Formdata[]>([])
const [sendData, SetsendData] = React.useState<any[]>([