HOC for Styling
Example: Carousel
// Higher order component
import React from 'react'
// This could be named something more generic like Counter or Cycle
const CarouselContainer = (Comp) => {
class Carousel extends React.Component {
constructor() {
super();
this.state = {
index: 0
};
this.previous = () => {
const { index } = this.state;
if (index > 0) {
this.setState({index: index - 1})
}
};
this.next = () => {
const { index } = this.state;
this.setState({index: index + 1})
}
}
render() {
return (
<Comp
{...this.props}
{...this.state}
previous={this.previous}
next={this.next}/>
)
}
}
return Carousel
};
export default CarouselContainer;Using the HOC
Usage
Last updated