Invalid Hook call

Please help, I am trying to useSate, I have imported it in from React

import React, {useState} from 'react';

I am then trying to call it to set a modal to false in my constructor:
const [modalOpen, setModalOpen ] = useState(false)

now getting error: InvariantViolation: Invalid Hook Call


You can’t use Hooks inside a class component (docs).

Thanks so what do I do then? I need it to be a class component as I am using state

Then use setState instead.

You can have state in a function component, that is what Hooks are for.

You have to choose what type of component you want. You don’t have to use classes, and you don’t have to use Hooks. You can have a mix of both in the application (not at the same time, in the same component obviously).

Can you post a link to your code on something like codesandbox?