react hooks typescript reuseable table
import axios from 'axios';
import SomeInterface from '../../../interfaces/SomeInterface.interface';
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string>("");
const [something, setSomething] = useState<SomeInterface>();
getSomething = () => {
axios.get<SomeInterface[]>(process.env.REACT_APP_BASE_API_URL + '/something', {
headers: {
"Content-Type": "application/json"
},
})
.then(response => {
setSomething(response.data);
// HERE - Printing to console the array of HEADERS
console.log(Object.keys(response.data[0]));
setLoading(false);
})
.catch(ex => {
const error = ex.response.status === 404
? "Resource Not found"
: "An unexpected error has occurred";
setError(error);
setLoading(false);
});
}