Reactjs SWR hook with next.js-typescript/issue

Reactjs SWR hook with next.js-typescript/issue,reactjs,typescript,next.js,swr,Reactjs,Typescript,Next.js,Swr,我在这里发布了一些关于SWR钩子的问题,因为在我尝试使用它的过程中有点困难,因为我遇到了一些问题 现在这一次错误似乎很小 我想做的是在API triying中设置一个断点来获取一些数据(顺便说一下,我正在使用axios),现在的问题是,我必须从useSWR中解构{data},因为这是我从axios接收的数据,我认为这导致了一个争论的问题,为了让一切都能顺利进行,我必须把这个争论转到钩子上 让我给你看一些代码 使用useSWR const Part1 = () => { const ro

我在这里发布了一些关于SWR钩子的问题,因为在我尝试使用它的过程中有点困难,因为我遇到了一些问题

现在这一次错误似乎很小

我想做的是在API triying中设置一个断点来获取一些数据(顺便说一下,我正在使用axios),现在的问题是,我必须从useSWR中解构
{data}
,因为这是我从axios接收的数据,我认为这导致了一个争论的问题,为了让一切都能顺利进行,我必须把这个争论转到钩子上

让我给你看一些代码

使用useSWR

const Part1 = () => {
  const router = useRouter();

  const [searchBar, setSearchBar] = useState<boolean>(false);

  const [userId, setUserId] = useState<dataObject>({});
  const [results, setResults] = useState<string>("");

  // Searchbar users

  useEffect(() => {
    const auth: dataObject = JSON.parse(localStorage.getItem("Auth"));
    setUserId(auth);
  }, []);

  const { data }: multipleUsers = useSWR(
    () => "http://localhost:5000/api/user/allU/" + userId.user.id,
    fetcher,
    "",
    data
  );
目标:那里发生了什么,我如何解决这个问题?具体原因是什么?为什么

谢谢你的时间

更新

我更改了代码,这是出现的错误

 const { data }: multipleUsers = useSWR<user[]>(
    () => "http://localhost:5000/api/user/allU/" + userId.user.id,
    fetcher,
    ""
  );

下面是
useSWR
函数签名():

只有一个变量有3个参数,就是这个:

readonly [
    Key,
    Fetcher<Data> | null,
    SWRConfiguration<Data, Error> | undefined
  ]
只读[
钥匙
取数器|空,
SWR配置|未定义
]
请看第三种参数类型:

SWRConfiguration<Data, Error> | undefined
SWRConfiguration |未定义
甚至不检查源代码,它可能是某种对象。你通过了什么?空字符串:
“”


删除此参数或传递配置对象。

以下是
useSWR
函数签名():

只有一个变量有3个参数,就是这个:

readonly [
    Key,
    Fetcher<Data> | null,
    SWRConfiguration<Data, Error> | undefined
  ]
只读[
钥匙
取数器|空,
SWR配置|未定义
]
请看第三种参数类型:

SWRConfiguration<Data, Error> | undefined
SWRConfiguration |未定义
甚至不检查源代码,它可能是某种对象。你通过了什么?空字符串:
“”


删除此参数或传递配置对象。

我将代码更改为`const{data}:multipleUsers=useSWR(()=>“”+userId.user.id,fetcher,”;`但它会抱怨,因为没有4个参数是对的,因为你不能传递4个参数,因为它不支持第4个参数,正如我在回答中所写的。请用更新的代码和完整的错误消息更新你的帖子。@Diego你不小心建议编辑我的回答。请编辑你自己的问题帖子。打字脚本不是很简单,有很多地方会迷路。很高兴我能帮忙!我将代码更改为`const{data}:multipleUsers=useSWR(()=>“+userId.user.id,fetcher,”);`但它会抱怨,因为没有4个参数是对的,因为你不能传递4个参数,因为它不支持第4个参数,正如我在回答中所写的。请用更新的代码和完整的错误消息更新你的帖子。@Diego你不小心建议编辑我的回答。请编辑你自己的问题帖子。打字脚本不是很简单,有很多地方会迷路。很高兴我能帮忙!
| readonly [Key]
| readonly [Key, Fetcher<Data> | null]
| readonly [Key, SWRConfiguration<Data, Error> | undefined]
| readonly [
    Key,
    Fetcher<Data> | null,
    SWRConfiguration<Data, Error> | undefined
  ]
readonly [
    Key,
    Fetcher<Data> | null,
    SWRConfiguration<Data, Error> | undefined
  ]
SWRConfiguration<Data, Error> | undefined