my-component-library icon indicating copy to clipboard operation
my-component-library copied to clipboard

React hooks not working

Open rdourado-synd opened this issue 1 year ago • 1 comments

I tried adding a simple useState hook in one of the components and it throws an error: Cannot read properties of null (reading 'useState'). Do you know how to fix this? Thank you!

rdourado-synd avatar Jul 05 '24 18:07 rdourado-synd

Hello @rdourado-synd, I think the following are the possible issues for the above error.

  1. Make sure to import the useState hook from react library as "import {useState} from 'react'; "
  2. Make sure to use it inside a functional component as const MyComponent = () => {

const [ temp, setTemp ] = useState('');

return (.......);

}

I hope that helps.

saiTharunDusa avatar Jul 11 '24 21:07 saiTharunDusa