Accepted answer
const [user, setuser] = usestate(null);

since you havn't given this a type, typescript has to try to infer it. it sees you passed in a null, so it assumes this state is (and always will be) null. instead, you need to specify the type, as in:

interface userdata {
  username: string;
  password: string;
  prevstate: null

const [user, setuser] = usestate<userdata | null>(null);


if you fetching data from api you need this:

import react, { usestate, useeffect } from 'react'
import axios from 'axios';

const mycomponent = () => {
const [data, setdata] = usestate<any | null>(null);
const fetchdata = () => {
(...) //axios.get() or async if u await data.
useeffect(() =>{
}, [])

Related Query

More Query from same tag