未验证 提交 ccf26a85 编写于 作者: M Michael Aufreiter 提交者: GitHub

Guard useSwr() to avoid sending invalid request (#20671)

上级 fb9ca494
......@@ -5,7 +5,10 @@ const fetcher = (url) => fetch(url).then((res) => res.json())
export default function User() {
const router = useRouter()
const { data, error } = useSwr(`/api/user/${router.query.id}`, fetcher)
const { data, error } = useSwr(
router.query.id ? `/api/user/${router.query.id}` : null,
fetcher
)
if (error) return <div>Failed to load user</div>
if (!data) return <div>Loading...</div>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册