Skip to content

Commit

Permalink
Test generic function components
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Apr 1, 2020
1 parent e2b4313 commit 0268a8c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Samples/TodoMVC/src/TodoMVC.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,19 @@ type TodoItem() =
]
)

type TodoFooter() =
inherit FunctionComponent<{| count: int
let TodoFooter<'T> =
FunctionComponent.Of<{| count: int
completedCount: int
onClearCompleted: unit->unit
nowShowing: string |}>(fun props ->
nowShowing: string
genericProp: 'T |}>
(memoizeWith = (fun _p1 _p2 -> true),
render = (fun props ->
printfn "Rendering FOOTER"
Hooks.useEffect((fun () ->
printfn "This should be printed only once"
), [||])

let activeTodoWord =
"item" + (if props.count = 1 then "" else "s")
let clearButton =
Expand Down Expand Up @@ -184,7 +192,7 @@ type TodoFooter() =
clearButton
]
]
)
))

type TodoApp() =
inherit FunctionComponent<{| model: TodoModel |}>(fun props ->
Expand Down Expand Up @@ -269,11 +277,12 @@ type TodoApp() =
todos.Length - activeTodoCount
let footer =
if activeTodoCount > 0 || completedCount > 0 then
FunctionComponent.Render<TodoFooter,_>
TodoFooter
{| count = activeTodoCount
completedCount = completedCount
nowShowing = state.current.nowShowing
onClearCompleted = clearCompleted |}
onClearCompleted = clearCompleted
genericProp = 1 |}
else nothing
let main =
if todos.Length > 0 then
Expand Down

0 comments on commit 0268a8c

Please sign in to comment.