score:98

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);

score:25

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.
setData(fetchData)
}
}
useEffect(() =>{
    fetchData()
}, [])

Related Query

More Query from same tag