裝飾採用組件的數組。
var Decorators = [
{
component: React.createClass({
render() {
return (
<div>
<i className="fa fa-chevron-circle-left fa-3x" onClick={this.props.previousSlide} aria-hidden="true"></i>
</div>
)
}
}),
position: 'CenterLeft',
style: {
padding: 20
}
},
{
component: React.createClass({
render() {
return (
<div>
<i className="fa fa-chevron-circle-right fa-3x" onClick={this.props.nextSlide} aria-hidden="true"></i>
</div>
)
}
}),
position: 'CenterRight',
style: {
padding: 20
}
}
];
新增的優化,以減少渲染計數(加shouldComponentUpdate)
var Decorators = [
{
component: React.createClass({
shouldComponentUpdate(nextProps, nextState) {
return this.props.currentSlide !== nextProps.currentSlide;
},
render() {
return (
<div>
<i className="fa fa-chevron-circle-left fa-3x" onClick={this.props.previousSlide} aria-hidden="true"></i>
</div>
)
}
}),
position: 'CenterLeft',
style: {
padding: 20
}
},
{
component: React.createClass({
shouldComponentUpdate(nextProps, nextState) {
return this.props.currentSlide !== nextProps.currentSlide;
},
render() {
return (
<div>
<i className="fa fa-chevron-circle-right fa-3x" onClick={this.props.nextSlide} aria-hidden="true"></i>
</div>
)
}
}),
position: 'CenterRight',
style: {
padding: 20
}
}
];