React Base Fiddle (JSX)
Starting point for creating JSFiddles with React.
by Akshay Jain
HTML
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/recompose/0.26.0/Recompose.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
Babel + JSX
const { compose, withState, lifecycle, withHandlers } = Recompose;
function Test(props) {
return (<div style={{position: 'relative', top: '50%', left: '50%'}}>
<pre style={{width: '250px', height: '250px', border: '1px solid black'}}>
{JSON.stringify(props, null, 2)}
</pre>
</div>)
}
const Randomizer = compose(
withState('knightPosition', 'moveKnight', [1,7]),
lifecycle({
componentDidMount() {
this.interval = setInterval(() => {
this.props.moveKnight([Math.floor(Math.random() * 8), Math.floor(Math.random() * 8)]);
}, 500)
},
componentWillUnmount() {
clearInterval(this.interval)
}
})
)(Test)
ReactDOM.render(
<Randomizer />,
document.getElementById('container')
)