Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
    )
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading