Berke Özbek
Berke Özbek

Reputation: 59

why can't i use useState in react

When I want to use useState, one of the hooks structures, in react, he gets angry with me const [apple, setApple] = useState(false). I have never encountered such a problem before. Could there be a place I overlooked?enter image description here

Upvotes: 0

Views: 1000

Answers (1)

vahid ghadiri
vahid ghadiri

Reputation: 345

you have to write your hook inside of a component, when you start the name of component with Lowercase letters, it defines as a normal function not a component, change it to Capital letters...

import React from "react"

export default function Apple(props) {

    const [apple, setApple] = React.useState(false);

    return (
        <div>
          YOUR_CONTENT
        </div>
    )
}

Upvotes: 1

Related Questions