Skip to content

Commit fee00b5

Browse files
committed
add component
1 parent 83eca8d commit fee00b5

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

src/App.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
module App
1+
module Root
22

33
open Feliz
44
open Browser.Dom
55
open Fable.Core.JsInterop
66

7-
87
importSideEffects "./index.css"
98

10-
119
let root = ReactDOM.createRoot(document.getElementById "root")
12-
root.render(App.Components.Counter())
10+
root.render(App.Main.El())

src/App.fsproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<Compile Include="Components.fs" />
9-
<Compile Include="Components.test.fs" />
8+
<Compile Include="components/Counter.fs" />
9+
<Compile Include="Main.fs" />
10+
<Compile Include="Main.test.fs" />
1011
<Compile Include="App.fs" />
1112
</ItemGroup>
1213

src/Components.fs renamed to src/Main.fs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ open Feliz
44
open Fable.Core
55
open Fable.Core.JsInterop
66

7-
type Components() =
7+
module Main =
88

99
[<ReactComponent>]
10-
static member Counter() =
11-
let (count, setCount) = React.useState(0)
12-
10+
let El() =
11+
1312
let viteLogo: unit -> unit = import "default" "./assets/vite.svg"
1413
let reactLogo: unit -> unit = import "default" "./assets/react.svg"
1514
importSideEffects "./App.css"
@@ -51,20 +50,7 @@ type Components() =
5150
]
5251
]
5352
Html.h1 "Vite + React + Feliz"
54-
Html.div [
55-
prop.className "card"
56-
prop.children [
57-
Html.button [
58-
prop.onClick (fun _ -> setCount(count + 1))
59-
prop.text $"count is {count}"
60-
]
61-
Html.p [
62-
Html.text "Edit "
63-
Html.code "src/App.fs"
64-
Html.text " and save to test HMR"
65-
]
66-
]
67-
]
53+
Components.Counter.El()
6854
Html.p [
6955
prop.className "read-the-docs"
7056
prop.text " Click on the Vite, React or Fable Vite Plugin logos to learn more"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open Fable.Jester
1414
open App
1515

1616
Jest.describe("Counter component", fun () ->
17-
let element = RTL.render(Components.Counter())
17+
let element = RTL.render(App.Main.El())
1818

1919
Jest.test("should render initial count", fun () ->
2020
let countElement = element.getByText("count is 0")

src/components/Counter.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module App.Components.Counter
2+
3+
open Feliz
4+
5+
[<ReactComponent>]
6+
let El() =
7+
let (count, setCount) = React.useState(0)
8+
9+
Html.div [
10+
prop.className "card"
11+
prop.children [
12+
Html.h2 "Counter.fs Yes"
13+
Html.button [
14+
prop.onClick (fun _ -> setCount(count + 1))
15+
prop.text $"count is {count}"
16+
]
17+
Html.p [
18+
Html.text "Edit "
19+
Html.code "src/App.fs"
20+
Html.text " and save to test HMR yes"
21+
]
22+
]
23+
]
24+

0 commit comments

Comments
 (0)