Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@haywoood
Created October 20, 2016 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haywoood/096f8657306a86832e6df1109a0211ce to your computer and use it in GitHub Desktop.
Save haywoood/096f8657306a86832e6df1109a0211ce to your computer and use it in GitHub Desktop.
// Translation of the clock example on http://reagent-project.github.io/
import {state, ui, render} from "essence"
const timerState = state({
value: new Date(),
color: "#f34"
})
setInterval(() => timerState.value = new Date(), 1000)
const Greeting = props => <h1>{props.children}</h1>
const Clock = ui(() => {
const timeStr = timerState.value.toTimeString().split(" ")[0]
return (
<div className="example-clock" style={{color: timerState.color}}>
{timeStr}
</div>
)
})
const ColorInput = ui(() => (
<div className="color-input">
Time color: <input type="text" value={timerState.color}
onChange={(e) => timerState.color = e.target.value} />
</div>
))
const SimpleExample = () => (
<div>
<Greeting>Hello world, it is now</Greeting>
<Clock />
<ColorInput />
</div>
)
render(<SimpleExample />, "root")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment