尝试通过组件传递参数

发布于 2025-02-11 09:07:25 字数 1021 浏览 0 评论 0原文

因此,我正在使用电影DB API创建一个应用程序,并且我的演员组成部分将演员ID传递给,以及当我尝试使用该ID链接到人网页时,由于某种原因,我会传递对象。我试图通过数字,有什么办法做到这一点吗?

    import React from 'react';
// Styles
import { Wrapper, Image } from './Actor.style'

import { Link } from 'react-router-dom';

const Actor = ({name, character, imageUrl, personId}) => {
    console.log(personId);
    return(
        <Wrapper>
            <Link to={`/person/${personId}`}>
                <Image src={imageUrl} alt='actor-thumb' />
            </Link>

            <h3>{name}</h3>
            <p>{character}</p>
        </Wrapper>
    )
}

导出默认演员;

因此,我将这些组件输出到屏幕:

,当我单击其中一个时,我会收到此错误:

So I am creating an app using the movie DB API and I have this Actor component where I am passing the actor id to and when I try to use that Id to link to the person webpage for some reason I am passing an object instead. I am trying to pass the number, is there any way to do this?

    import React from 'react';
// Styles
import { Wrapper, Image } from './Actor.style'

import { Link } from 'react-router-dom';

const Actor = ({name, character, imageUrl, personId}) => {
    console.log(personId);
    return(
        <Wrapper>
            <Link to={`/person/${personId}`}>
                <Image src={imageUrl} alt='actor-thumb' />
            </Link>

            <h3>{name}</h3>
            <p>{character}</p>
        </Wrapper>
    )
}

export default Actor;

So I have these components output to the screen:
enter image description here

And when I click on one of them I get this error:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文