'why can't i use useState in react
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 |