Javascript {props.props.title}?为什么不{props.title}?

Javascript {props.props.title}?为什么不{props.title}?,javascript,reactjs,next.js,react-props,Javascript,Reactjs,Next.js,React Props,我还在学习如何将API数据与react和nextjs一起使用。但是,为什么我的函数只在我编写{props.props.title}而不是我所期望的{props.title}时才起作用 代码: 功能测试项目(道具){ 控制台日志(道具) 返回( {props.props.title} ) } 导出默认测试项 读到有关呼叫道具的文章时,我错过了什么吗 我将testItems称为algolia react instantsearch的热门产品: const InfiniteHits = ( {hit

我还在学习如何将API数据与react和nextjs一起使用。但是,为什么我的函数只在我编写
{props.props.title}
而不是我所期望的
{props.title}
时才起作用

代码:

功能测试项目(道具){
控制台日志(道具)
返回(
{props.props.title}
)
}
导出默认测试项
读到有关呼叫道具的文章时,我错过了什么吗

我将testItems称为algolia react instantsearch的热门产品:

const InfiniteHits = ( {hits, refineNext, hasMore} ) => {
  return(
    <div className="row">
      {hits.map((hit, index) => (
        <Hits props={hit} key={index} />
      ))}
      {hasMore &&
        <button className="ais-InfiniteHits-loadMore" onClick={refineNext}>Show more</button>
      }
    </div>
  )
};
const InfiniteHits=({hits,refineNext,hasMore})=>{
返回(
{hits.map((hit,index)=>(
))}
{哈斯莫尔&&
显示更多
}
)
};

这就是问题所在

<Hits props={hit} key={index} />

你应该这样通过

<Hits hit={hit} key={index} />

这就是问题所在

<Hits props={hit} key={index} />

你应该这样通过

<Hits hit={hit} key={index} />

我相信发生的事情是,您正在将一个prop传递到名为
props
的组件中,该组件是一个具有名为
props
的属性的对象(
{props:{title:{some title}

如果您想将其作为
prop.title
获取,您可以像这样分散属性


这将把
props
上的每个键作为一个道具传入。

我相信发生的事情是将一个道具传递到名为
props
的组件中,该组件是一个具有名为
props
属性的对象(
{props:{title:{some title}

如果您想将其作为
prop.title
获取,您可以像这样分散属性


这将把
道具上的每个键作为道具传入。

您正在将
道具作为道具传入组件。

如果你只想使用道具一次,或者不想再使用道具。您可以在testItems组件中使用解构,例如
函数testItems({props})
,或者在
Hit
组件中传递
标题
和其他道具(如果有的话),例如

您正在将
道具
作为道具传递到组件中。
如果你只想使用道具一次,或者不想再使用道具。您可以在testItems组件中使用解构,例如
函数testItems({props})
,或者在
Hit
组件中传递
标题
和其他道具(如果有的话),例如

如何调用
testItems
组件?@MuhammadZeeshan Hi,我在上面加了我的名字,你需要在像函数testItems({props})@MattBerg这样的对象中传递props,但这不只是一个对象吗?就像我可以做{props}或{随便什么}这些不一样吗?你如何调用
testItems
组件?@MuhammadZeeshan嗨,我补充了我如何在上面调用它你需要在像函数testItems({props})这样的对象中传递props,但这不只是一个对象吗?就像我可以做{props}或{随便什么}这些不都一样吗?这不就是
props.hit.title
?OP希望能够
props.title
OP提供的代码段中没有“title”。这里的问题是OP将道具作为“道具”传递到他们的子组件中,并将其设置为子react组件接收的道具上的道具。@AdamLeBlanc正确地将控制台中的道具更改为hit及其
props.hit.title
,这难道不会使它成为
props.hit.title
?OP希望能够
props.title
OP提供的代码段中没有“title”。这里的问题是OP将道具作为“道具”传递到他们的子组件中,并将其设置为子react组件接收的道具上的道具。@AdamLeBlanc正确地将控制台中的道具更改为hit及其
props.hit.title
Awesome!我不知道你可以像这样使用排列操作符。它不喜欢逗号,但在不使用someas的情况下可以完美地工作!我不知道你可以像这样使用排列操作符。它不喜欢逗号,但在没有逗号的情况下可以完美地工作