首页
注册
登录
zmaplex
V2EX 第 417565 号会员,加入于 2019-06-01 21:37:55 +08:00
zmaplex
提问
技术话题
好玩
工作信息
交易信息
城市相关
根据 zmaplex 的设置,主题列表被隐藏
二手交易
相关的信息,包括已关闭的交易,不会被隐藏
zmaplex 最近回复了
3 天前
回复了
devzhaoyou
创建的主题
›
React
›
React hook 使用疑惑
import { useState } from 'react';
import useSWR from 'swr';
const fetchMoreData = async (count: number) => {
await new Promise((resolve) => setTimeout(resolve, count * 100));
return count
}
export default function Demo() {
const [count, setCount] = useState(0);
const { data, error, isLoading } = useSWR(`count-${count}-swr`, async () => {
if (count == 5) {
throw new Error("count is 5")
}
return await fetchMoreData(count)
})
const handleClick = () => {
setCount(0);
};
if (isLoading) return <div>Loading...</div>
if (error) return <div>{`${error}`}</div>
return (<div >
<div>{data}</div>
<button onClick={() => setCount(count + 1)}>+</button>
<button onClick={handleClick}>handleClick</button>
</div>)
}
3 天前
回复了
devzhaoyou
创建的主题
›
React
›
React hook 使用疑惑
用 swr
https://gist.github.com/zmaplex/6c4d4eacea1df7fcfccf3fe4c17f4a0a
»
zmaplex 创建的更多回复
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
我们的愿景
·
实用小工具
·
3538 人在线
最高记录 6543
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms ·
UTC 04:39
·
PVG 12:39
·
LAX 21:39
·
JFK 00:39
Developed with
CodeLauncher
♥ Do have faith in what you're doing.