I am trying to use useEffect inside of my cockpit function that returns a couple of elements, but I get this weird error saying that "Line 6: React Hook "useEffect" is called in function "cockpit" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks".
But surely my cockpit component is a function?
import React, { useEffect } from 'react'
import classes from './Cockpit.css'
const cockpit = (props) => {
useEffect(() => {
console.log('I work!')
})
const assignedClasses = []
let btnClass = ''
if (props.showPersons) {
btnClass = classes.Red;
}
if (props.persons.length <= 2) {
assignedClasses.push(classes.red)
}
if (props.persons.length <= 1) {
assignedClasses.push(classes.bold)
}
return (
<div className={classes.Cockpit}>
<h1>{props.title}</h1>
<p className={assignedClasses.join(' ')}>HELLO, HELLO!</p>
<button
className={btnClass}
onClick={props.clicked}>Click me!</button>
</div>
)
}
export default cockpit