将整个前端部分页面处理id的方式,由使用 params.id 的方式全部迁移到 React.use(params) 这种方式
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import type React from "react"
|
import * as React from "react"
|
||||||
import { useState, useEffect, use } from "react"
|
import { useState, useEffect } from "react"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
@@ -12,6 +12,12 @@ import { ArrowLeft, Plus, Trash } from "lucide-react"
|
|||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { toast, Toaster } from "sonner"
|
import { toast, Toaster } from "sonner"
|
||||||
|
|
||||||
|
// 为React.use添加类型声明
|
||||||
|
declare module 'react' {
|
||||||
|
function use<T>(promise: Promise<T>): T;
|
||||||
|
function use<T>(value: T): T;
|
||||||
|
}
|
||||||
|
|
||||||
interface Device {
|
interface Device {
|
||||||
id: number
|
id: number
|
||||||
memo: string
|
memo: string
|
||||||
@@ -40,7 +46,7 @@ export default function EditProjectPage({ params }: { params: { id: string } })
|
|||||||
const [project, setProject] = useState<Project | null>(null)
|
const [project, setProject] = useState<Project | null>(null)
|
||||||
const [password, setPassword] = useState("")
|
const [password, setPassword] = useState("")
|
||||||
const [confirmPassword, setConfirmPassword] = useState("")
|
const [confirmPassword, setConfirmPassword] = useState("")
|
||||||
const id = params.id
|
const { id } = React.use(params)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchProject = async () => {
|
const fetchProject = async () => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import React from "react"
|
||||||
import { useState, useEffect } from "react"
|
import { useState, useEffect } from "react"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
@@ -51,7 +52,14 @@ interface SubUser {
|
|||||||
typeId: number
|
typeId: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProjectDetailPage({ params }: { params: { id: string } }) {
|
interface ProjectDetailPageProps {
|
||||||
|
params: {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProjectDetailPage({ params }: ProjectDetailPageProps) {
|
||||||
|
const { id } = use(params)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
const [isDevicesLoading, setIsDevicesLoading] = useState(false)
|
const [isDevicesLoading, setIsDevicesLoading] = useState(false)
|
||||||
@@ -60,7 +68,6 @@ export default function ProjectDetailPage({ params }: { params: { id: string } }
|
|||||||
const [devices, setDevices] = useState<Device[]>([])
|
const [devices, setDevices] = useState<Device[]>([])
|
||||||
const [subUsers, setSubUsers] = useState<SubUser[]>([])
|
const [subUsers, setSubUsers] = useState<SubUser[]>([])
|
||||||
const [activeTab, setActiveTab] = useState("overview")
|
const [activeTab, setActiveTab] = useState("overview")
|
||||||
const { id } = use(params)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchProjectProfile = async () => {
|
const fetchProjectProfile = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user