You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
734 B

4 years ago
  1. package com.example.playscalajsreact.component
  2. object IntEditor {
  3. import japgolly.scalajs.react._
  4. import japgolly.scalajs.react.vdom.html_<^._
  5. import japgolly.scalajs.react.MonocleReact._
  6. import japgolly.scalajs.react.extra._
  7. import monocle.macros.Lenses
  8. val component = ScalaComponent
  9. .builder[StateSnapshot[Int]]
  10. .render_P { stateSnapshot =>
  11. <.span(
  12. ^.paddingLeft := "6ex", // leave some space for ReusabilityOverlay
  13. <.button(
  14. s"Current value is ${stateSnapshot.value}. Click to increment",
  15. ^.onClick --> stateSnapshot.modState(_ + 1),
  16. )
  17. )
  18. }
  19. .configure(ReusabilityOverlay.install)
  20. .build
  21. def apply(ss: StateSnapshot[Int]) = component(ss)
  22. }