Currently trying to convert a part of the codebase into Flow. While I was tackling with API calls, I have created a hook to abstract the functionality. However when I tried to import it, the function always returned with a later-added any type.
// @flow
import {useState, useEffect} from 'react';
export default function useApi<T>(
apiCall: (...args: any[]) => Promise<T>,
initialValue:T[]=[]
): T[] {
const [data, setData] = useState(initialValue);
useEffect(() => {
apiCall().then(setData).catch(console.error);
}, [apiCall]);
return data;
}
import './App.css';
import useApi from './hooks/useApi';
import { getOffers } from './service/Offers';
import { useCallback } from "react";
import Header from "./components/Header";
import Card from "./components/Card";
function App() {
const getOffersMemo = useCallback(() => getOffers(), []);
const offers = useApi(getOffersMemo); // type => OfferModel[] | any
return (//SomeTemplate);
}
export default App;
However when I use export without default keyword it doesn't add any type. What is the reason for this behavior?