nextjs开发react时候从路由获取id请求详情,会执行多次。id的log出现了4次,res出现了3次 有时候id第一次log获取不到,后续能获取到 export default function test({ data }: Props) { const router = useRouter(); const { id } = router.query; const [builder, setbuilder] = useState(data); const getDetail = useCallback(async () => { console.log(id); if (!id) return; const res = await sanity.getBuilder({ id: id.toString(), }); console.log(res); setbuilder(res); }, []); getDetail(); }