Answers for "react hooks typescript reuseable table"

0

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);
      });
}
Posted by: Guest on October-12-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language