File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
1
package myapp .components
2
2
3
+ import japgolly .scalajs .react ._
4
+ import japgolly .scalajs .react .vdom .html_<^ ._
5
+ import myapp .Config
6
+ import org .scalajs .dom .document
7
+
8
+ val Counter = ScalaFnComponent
9
+ .withHooks[Unit ]
10
+ .useState(0 )
11
+ .useEffectBy((_, count) =>
12
+ Callback {
13
+ document.title =
14
+ if (count.value == 0 ) Config .title
15
+ else s " You clicked ${count.value} times "
16
+ }
17
+ )
18
+ .render((_, count) =>
19
+ < .div(
20
+ < .p(s " You clicked ${count.value} times " ),
21
+ < .button(
22
+ ^ .onClick --> count.modState(_ + 1 ),
23
+ " Click me"
24
+ )
25
+ )
26
+ )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package myapp.pages
3
3
import japgolly .scalajs .react ._
4
4
import japgolly .scalajs .react .vdom .html_<^ ._
5
5
import myapp .Config
6
+ import myapp .components .Counter
6
7
import scala .scalajs .js .annotation .JSExportTopLevel
7
8
import scala .scalajs .js
8
9
import scala .scalajs .js .annotation .JSImport
@@ -17,7 +18,9 @@ val Homepage = ScalaComponent
17
18
< .div(
18
19
^ .className := styles(" home" ),
19
20
< .h1(Config .title),
20
- Config .description.map(text => < .p(text, ^ .key := text)).toVdomArray
21
+ Config .description.map(text => < .p(text, ^ .key := text)).toVdomArray,
22
+ < .hr,
23
+ Counter ()
21
24
)
22
25
)
23
26
.build
You can’t perform that action at this time.
0 commit comments