next.js 未定义不是有效的JSON

zynd9foi  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(124)

我在这个非常简单的React组件上得到了上面的错误,但对我来说一切似乎都很好,所以我不明白为什么我会得到错误。我下一个使用。js 13.3.0.
未捕获的语法错误:“undefined”不是有效的JSON。parse()

"use client";

import { useState } from "react";

interface Props {
  handleClick: () => void;
  name: string;
}

const Button = ({ handleClick, name }: Props) => {
  console.log(`${name} renderizado`);
  return <button onClick={handleClick}>{name}</button>;
};

export default function Home() {
  const [countOne, setCountOne] = useState(0);
  const [countTwo, setCountTwo] = useState(0);

  return (
    <>
      <Button
        handleClick={() => setCountOne((prev) => prev + 1)}
        name="button1"
      />
      <Button
        handleClick={() => setCountTwo((prev) => prev + 1)}
        name="button2"
      />
    </>
  );
}

堆栈跟踪

66bbxpm5

66bbxpm51#

不能给予具体的解决方案,但 prop 界面可以做到这一点:

interface Props {
  handleClick: () => void;
  name: string;
  children?: React.ReactNode;
}

相关问题