Skip to content

haywoood/essence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

import {update, state, ui, render} from "@haywoood/essence"

const appState = state({
  count: 0
})

const resetCount = () => {
  update(appState, appState => {
    appState.count = 0
    return appState
  })
}

const incrementCount = () => {
  update(appState, appState => {
    appState.count = appState.count + 1
    return appState
  })
}

const decrementCount = () => {
  update(appState, appState => {
    appState.count = appState.count - 1
    return appState
  })
}

const App = ui(() => {
  return (
    <div style={{display: "flex", flexDirection: "column", width: 300}}>
      <h1 onClick={resetCount}>
        <strong>current count: {appState.count}</strong>
      </h1>

      <button onClick={incrementCount}>
        increment count
      </button>

      <br />

      <button onClick={decrementCount}>
        decrement count
      </button>
    </div>
  )
})

render(<App />, document.getElementById("root"))

This was composed to teach beginners, no frameworks to learn, 4 functions, just focus on creating functions that return html and functions that modify data.

MIT

About

web apps with next to no library code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published