DEV Community

Usestate hook not working inside arrow component.

Simone Aronica on December 17, 2019

The story So I'm trying to replicate a Material Design text field, and I think I've managed to do that pretty well, as in this Code Sand...
Collapse
 
stereobooster profile image
stereobooster

Post link to full example. Code of the component is ok codesandbox.io/s/goofy-feynman-vl3ny

Do you try to call component as function instead of using as component?

Collapse
 
itssimondev profile image
Simone Aronica • Edited

I've edited the post.

Collapse
 
stereobooster profile image
stereobooster

Post link to codesandbox (not preview but sandbox itslef) where we can see error.

Thread Thread
 
itssimondev profile image
Simone Aronica

I solved it. Apparently all I had to do was setting react as an external.

Collapse
 
daxsoft profile image
Michael Willian Santos

Are you importing React this way:

import React, { useState } from 'react' (correct),

rather than:

import React, { useState } from 'React' (incorrect)?

Collapse
 
itssimondev profile image
Simone Aronica • Edited

I am, my bad, I didn't specify: the issue is not when compiling, the issue is when running the code on a page.