React Base Fiddle (JSX)
Starting point for creating JSFiddles with React. This uses React with Addons.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-15.2.0.js"></script>
<script src="https://fb.me/react-dom-15.2.0.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container"></div>
CSS
span {
display: inline-block;
padding: 10px;
}
JavaScript 1.7
class Pagination extends React.Component {
constructor(props) {
super(props);
this.state = { current: 1 };
this.items = ['a', 'b', 'c'];
this.filteredItems = [];
this.prev = this.prev.bind(this);
this.next = this.next.bind(this);
this.set = this.set.bind(this);
}
componentWillMount() {
this.set();
}
prev() {
this.set(this.state.current - 1);
}
next() {
this.set(this.state.current + 1);
}
set(val = 1) {
if (val < 1) {
val = 1;
}
if (val > 5) {
val = 5;
}
this.setState({ current: val });
}
handleChange(e) {
let val = parseInt(e.target.value);
if (isNaN(val)) {
this.setState({ current: '' });
} else {
if (val < 1) {
val = 1;
}
if (val) {
this.set(val);
}
}
}
render() {
return (
<div>
<span onClick={this.prev}>prev</span>
<input type="text" value={this.state.current} onChange={this.handleChange.bind(this)} />
<span onClick={this.next}>next</span>
<br /><span>current: {this.state.current}</span>
</div>
)
}
}
ReactDOM.render(
<Pagination />,
document.getElementById('container')
);