'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



Solution 1:[1]

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>
    )
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1