Reactjs 功能组件默认道具与道具对象

在功能组件中,我们可以像这样传递道具。


function Country(props){


}

我们可以像这样传递默认道具值


function Country({name:'Sri Lanka',description:'blah! blah!'}){

    

}

然后我们可以将这样的道具传递给组件。


<Country name={'Germany'} description={'haha...'} />

但我确实想访问道具的历史对象。所以我做了


function Country({name:'Sri lanka',description:'haha',...props}){


}

但是当我console.log props是一个空对象时。在这里我想我可能也想传递props对象。我怎么做?


<Country name={'Germany'} description={'haha...'} />


互换的青春
浏览 77回答 1
1回答

元芳怎么了

当你使用你的 Country 组件时,你只需要传递 props 即可。像这样:<Country&nbsp;name={'Germany'}&nbsp;description={'haha...'}&nbsp;{...props}&nbsp;/>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript