diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -1,10 +1,42 @@ # Lustre -> A playground for building create web apps – powered by Gleam! +> A framework for building create web apps – powered by Gleam and React! [](https://hex.pm/packages/lustre) [](https://hexdocs.pm/lustre/) +```gleam +import gleam/int +import lustre +import lustre/element.{ button, div, p, text } +import lustre/event.{ dispatch, on_click } + +pub fn main () { + let app = lustre.application(0, update, render) + lustre.start(app, "#app") +} + +type Action { + Incr + Decr +} + +fn update (state, action) { + case action { + Incr -> state + 1 + Decr -> state - 1 + } +} + +fn render (state) { + div([], [ + button([ on_click(dispatch(Decr)) ], [ text("-") ]), + p([], [ text(int.to_string(state)) ]), + button([ on_click(dispatch(Incr)) ], [ text("+") ]) + ]) +} +``` + > ❗️ This package relies on Gleam's JavaScript FFI and will not work if your are > targeting Erlang. |