React Hook "useState" is called in Function

Asked

Viewed 294 times

-4

Good evening, I performed a CRUD project with Node, React and Mysql, but when trying to create routes in front-end, is generating the error:

React Hook "useState" is called in Function "Register" that is neither a React Function Component nor a custom React Hook Function. React Component Names must start with an uppercase Letter. [! [insert a description of the image here][1]][1]

As verified in the error, I tried to change the "useState" for "Usestate" (initial uppercase letter), but thus changing the function property.

import React, { useState } from "react"
import './style.css';
import Axios from 'axios'

function register() {
    const [nomeReg, setNomeReg] = useState('')
    const [dateReg, setDateReg] = useState('')
    const [cpfReg, setCpfReg] = useState('')
    const [emailReg, setEmailReg] = useState('')
    const [senhaReg, setSenhaReg] = useState('') 

When the code was a single route it was working correctly.

When compiling the React:

src\pages\register.js
  Line 6:35:   React Hook "useState" is called in function "register" 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
  Line 7:35:   React Hook "useState" is called in function "register" 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
  Line 8:33:   React Hook "useState" is called in function "register" 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
  Line 9:37:   React Hook "useState" is called in function "register" 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
  Line 10:37:  React Hook "useState" is called in function "register" 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

Search for the keywords to learn more about each error.

1 answer

-1


Solved by editing the function name to first uppercase letter:

Initial result:

Function Register() {

Final result:

Function Register() {

Browser other questions tagged

You are not signed in. Login or sign up in order to post.