所以,我有一个react函数,可以映射我的数组并渲染组件;
const urls = [
'http://localhost:3005/products/774944',
'http://localhost:3005/products/774945',
'http://localhost:3005/products/774946',
'http://localhost:3005/products/123581',
'http://localhost:3005/products/782691',
'http://localhost:3005/products/782485',
'http://localhost:3005/products/782486',
'http://localhost:3005/products/782487',
'http://localhost:3005/products/782488',
'http://localhost:3005/products/738471'];
ReactDOM.render( <App />, document.getElementById('root'));
let show_items = () => {
ReactDOM.render(urls.map((url)=>{
return(
<Item url={url}/>
)
}), document.getElementById('items'));
}
show_items()
我只想映射“ urls”数组中的前几项。我唯一想到的就是切片数组,但我很好奇是否有更好的方法