Ich bin ziemlich neu mit React. Also ich habe eine Schaltfläche, die, wenn ich klicke, zwischen ShowMore und ShowLess wechselt, aber ich möchte nur das erste Video des Arrays zeigen und mehr zeigen, wenn ich diesen Knopf drücke. Können Sie mir bitte helfen? Hier ist der Code:Ich möchte nur das erste Video im Array zeigen, indem ich auf eine Schaltfläche mit React.js
class Videos extends Component {
state = {
shouldHide: true
};
onClick = (e) => {
e.preventDefault();
if (this.state.shouldHide) {
this.setState({
shouldHide: false
});
} else {
this.setState({
shouldHide: true
});
}
};
addVideo = (e) => {
e.preventDefault();
this.props.showVideoModalAdd();
};
render =() => {
const { videos, allowEdit, specialistId } = this.props;
console.log(this.state);
const result = allowEdit || (videos && videos.length > 0) ? (
<div>
{videos.map(video => (
<div key={video.id}>
<Video
video={video}
allowEdit={allowEdit}
specialistId={specialistId}
/>
</div>
))}
{allowEdit && (
<span className="edit pull-right">
<a href="#" onClick={this.addVideo}>+ Add Video</a>
<br /><br />
<a href="#" onClick={this.onClick}>
{this.state.shouldHide ? 'Show Less' : 'Show More'}
</a>
</span>
)}
</div>
) : null;
return result;
};
}
ich bisher weiß, dass ich die videos.map ändern sollte, aber nicht sicher, wie