English 中文(简体)
I m 采用第14号手法和文字。 我发现错误,同时在editTask/[editTask]tsx制造动态路线。 尚未安装的用户
原标题:I m using nextJs 14 and typescript. I got error while creating dynamic routing in the editTask/[editTask].tsx. UseRouter wasa not mounted
  • 时间:2024-02-23 12:16:34
  •  标签:
  • typescript

如何在下一阶段采取动态路线 J. 14 采用打字方式? 进口{使用舱面},取自未出现的“next/router”错误。

// editTask/[editTask]/page.tsx
"use client";
import { useEffect, useState } from "react";
import axios from "axios";
进口{使用舱面},“next/router”;

const EditTask: React.FC = () => {
  const [title, setTitle] = useState("");
  const [description, setDescription] = useState("");
  const [completed, setCompleted] = useState(false);
  const router = useRouter();

  const { id } = router.query;

  useEffect(() => {
    const fetchTask = async () => {
      try {
        const res = await axios.get(`http://localhost:5555/tasks/${id}`);
        const task = res.data;
        setTitle(task.title);
        setDescription(task.description);
        setCompleted(task.completed);
      } catch (err) {
        console.error(err);
      }
    };

    if (id) {
      fetchTask();
    }
  }, [id]);

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();

    const updatedTask = {
      title,
      description,
      completed,
    };

    try {
      await axios.put(`http://localhost:5555/tasks/${id}`, updatedTask);
      router.push("/");
    } catch (err) {
      console.error(err);
    }
  };

  if (!id) return null;

这里的错误

进口{使用舱面},“next/router”;

const router = useRouter();

如何加以确定?

问题回答

如果你重新使用 app子,则试图利用子宫进口

import { useRouter } from  next/navigation 




相关问题
store data in memory with nestjs

I am trying to persist some data in my nestjs server so I can then use that data in my client app through http requests. I have created a products.service.ts file with the function getAllData() that ...

React Hook Form Error on custom Input component

I am having a problem when I use react hook form + zod in my application, in short the inputs never change value and I get the following error in the console: Warning: Function components cannot be ...

Updatable promises using proxy in JavaScript

EDIT: I ve updated this question, and the old question is moved here. A POC can be found on this jsfiddle or the snippet below GOAL: The goal here is to make or rather simulate a promise that can be ...

热门标签