[英]can someone tell me why this error appears to me?
錯誤:
React Hook "useState" is called in function "createFlight" that is
neither a React function component nor a custom React Hook function.
React component names must start with an uppercase letter react-
hooks/rules-of-hooks
我的代碼:
import React, {Component} from 'react';
import { useState } from 'react'
function createFlight(){
const [flight, setflight] = useState({flightNumber: "", departureTime: "", arrivalTime: "", departureDate: "", arrivalDate: "", cabin: "", economySeatsAvailable: "", businessSeatsAvailable: "", airport: "", from: "", to: "" });
}
export default createFlight;
將組件的名稱更改為以大寫字母開頭(如錯誤所示)。
function CreateFlight(){
如果相反,它應該是一個自定義鈎子,則需要在名稱中use
之前將其命名。 比如使用useCreateFlight
React 鈎子只能在 React 組件或其他 React 鈎子中調用。
React 組件必須是大寫的,就像這樣
function CreateFlight(){
const [flight, setflight] = useState();
}
然后可以像這樣渲染它們
<CreateFlight />
React 鈎子是將行為綁定到組件中的函數。 它們必須命名為“use...”,例如“useFlight”或其他名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.