Skip to content

Commit 41aa1e0

Browse files
committed
Improved Homepage
1 parent f77f611 commit 41aa1e0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
package myapp.components
22

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+
)

front/src/myapp/pages/Homepage.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package myapp.pages
33
import japgolly.scalajs.react._
44
import japgolly.scalajs.react.vdom.html_<^._
55
import myapp.Config
6+
import myapp.components.Counter
67
import scala.scalajs.js.annotation.JSExportTopLevel
78
import scala.scalajs.js
89
import scala.scalajs.js.annotation.JSImport
@@ -17,7 +18,9 @@ val Homepage = ScalaComponent
1718
<.div(
1819
^.className := styles("home"),
1920
<.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()
2124
)
2225
)
2326
.build

0 commit comments

Comments
 (0)