Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用react cookie setCookie-Type';{[name:string]:any;}';没有兼容的呼叫签名。ts(2349)_Reactjs_Typescript - Fatal编程技术网

Reactjs 使用react cookie setCookie-Type';{[name:string]:any;}';没有兼容的呼叫签名。ts(2349)

Reactjs 使用react cookie setCookie-Type';{[name:string]:any;}';没有兼容的呼叫签名。ts(2349),reactjs,typescript,Reactjs,Typescript,我在带有typescript的react应用程序中使用react cookie,但出现了错误 Cannot invoke an expression whose type lacks a call signature. Type '{ [name: string]: any; }' has no compatible call signatures.ts(2349) 将setCookie用作 const [setCookie] = useCookies(['example']); const

我在带有typescript的react应用程序中使用react cookie,但出现了错误

Cannot invoke an expression whose type lacks a call signature. Type '{ [name: string]: any; }' has no compatible call signatures.ts(2349)
setCookie
用作

const [setCookie] = useCookies(['example']);
const onLanguageSelect = (data: any) => {
  setCookie('example', data.value, { path: '/' });
};
错误出现在
setCookie
行上


如何修复此错误?在其他问题中阅读这个问题没有帮助,但是如果你知道一个资源可以帮助我找到正确的方向,那就太好了。

以下是react cookie自述:

const[cookies,setCookie,removeCookie]=useCookies(['cookie-name']);
setCookie
是返回数组的第二项

在您的代码中,您将获得第一项,
cookies
,您将其重命名为
setCookie

修复方法:

const setCookie=useCookies(['example'])[1];
小心数组分解,这很性感,但有时可能会误导