The error :
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
My code:
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;
Change the name of your component to start with an uppercase (as the error states).
function CreateFlight(){
If instead it is supposed to be a custom hook you need to name it prepending use in the name. Such as useCreateFlight
React hooks can only be called in React components or other React hooks.
React components have to be upper-case, like so
function CreateFlight(){
const [flight, setflight] = useState();
}
They can then be rendered like so
<CreateFlight />
React hooks are functions that bind behaviour into a component. They have to be named "use..." like, "useFlight" or something.