JimClayton
JimClayton

Reputation: 131

React useState cant be found in a component

using functional components to build out my ui. My register component cant find the import react, {useState} from 'react' It gives me back this error.

Failed to compile.

./src/pages/Register.js
  Line 10:31:  React Hook "useState" is called in function "register"
 which is neither a React function component or a custom React Hook function 
 react-hooks/rules-of-hooks

Search for the keywords to learn more about each error 

My App Structure is enter image description here

I have deleted react and reinstalled it with no luck


import React, { useContext, useState } from "react";

function register() {
  const initialState = {
    username: "",
    password: "",
    confirmPassword: "",
    email: "",
  };
  const [values, setvalues] = useState(initialState);
  return (
    <div>
      <h1>register</h1>
    </div>
  );
}

export default register;

Upvotes: 0

Views: 867

Answers (1)

Alejandro Lariccia
Alejandro Lariccia

Reputation: 369

Your problem is that components names must be capitalized in react. must be "Register" and no "register".

Upvotes: 5

Related Questions