Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

How to enable {useState} in react on Repl?

DeanArvin
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.

2 years ago

Voters

Comments

TopNew
3
Coder100
Coder100

Hi, have you tried doing:

const [count, setCount] = React.useState(4)
2 years ago
2
Coder100
Coder100

does it work?

@DeanArvin

2 years ago
1
DeanArvin
DeanArvin

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

2 years ago
1
Coder100
Coder100

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

@DeanArvin

2 years ago
1
Coder100
Coder100

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

2 years ago
Load more