Skip to content

Commit

Permalink
Add withReactHydrate
Browse files Browse the repository at this point in the history
  • Loading branch information
zaaack committed Mar 2, 2018
1 parent 53ce7a1 commit 98296f6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/react.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ module Program =
)

{ program with setState = setState }

/// Setup rendering of root React component inside html element identified by placeholderId
let withReactHyrate placeholderId (program:Elmish.Program<_,_,_,_>) =
let setState dispatch =
let viewWithDispatch = program.view dispatch
fun model ->
Fable.Import.ReactDom.hydrate(
lazyViewWith (fun x y -> obj.ReferenceEquals(x,y)) viewWithDispatch model,
document.getElementById(placeholderId)
)

{ program with setState = setState }

0 comments on commit 98296f6

Please sign in to comment.