hooksのuseReducerを使っているのですがTypeScriptの型規約がどうしてもエラーを出してしまいます。
//hooks export const useStudent = () => { const [state, dispatch] = useReducer(reducer, initialState); useEffect(()=> { dispacth(get()); }, []); const ChangeStudent = (id: number) => { return number + 1; }; return [state, ChangeStudent]; }; //student.tsx import { useStudent } from '../hooks/useStudnet.ts; const ListPage = () => { const [state, ChangeStudent] = useStudent() .... }
このようにするとTs側が
//useStudent()をホバーすると出てくるやつ (alias) useStudent(): (any[] | ((id: number) => number))[] import useStudent //関数として使おうとすると This expression is not callable. Not all constituents of type 'any[] | ((id: number) => number)' are callable. Type 'any[]' has no call signatures.
このように怒られてしまいます。解決策をご存知でしたらよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/15 08:40 編集
2020/06/15 08:44
2020/06/15 08:51
2020/06/15 08:56
2020/06/15 08:57
2020/06/15 12:34