Skip to content
Sign upLog in
← Back to Community

How to enable {useState} in react on Repl?

Profile icon
DeanArvin

Hello!

I'm having trouble finding out how to import the useState function into my React Repl.

I've used both

"import * as React from 'react'" and
"import * as React, {useState} from 'react'".

Neither seem to allow it to recognize the useState function I use later in the code.

Any help is very greatly appreciated.

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
DeanArvin
Comments
hotnewtop
Profile icon
Coder100

Hi, have you tried doing:

const [count, setCount] = React.useState(4)
Profile icon
Coder100

does it work?

@DeanArvin

Profile icon
DeanArvin

@Coder100
That was it! Thank you!
Is this type of thing specific to Repl?

Profile icon
Coder100

no, it's an import thing
also no problem :)

@DeanArvin

Profile icon
Coder100

@DeanArvin
Doing import * as React puts all the methods into the React 'object'.

Profile icon
matthewproskils