Skip to content

Commit

Permalink
change return signature of renderUI
Browse files Browse the repository at this point in the history
  • Loading branch information
luludotdev committed Nov 9, 2023
1 parent 77c1c5d commit d961a15
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/react/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ export const renderUI = (
game: Game<false>,
ui: ReactNode,
container?: HTMLDivElement,
): (() => void) => {
): { unmount(): void } => {
const div = container ?? document.createElement('div')
game.client.ui.add(div)

const root = createRoot(div)
root.render(<GameContext.Provider value={game}>{ui}</GameContext.Provider>)

return () => {
game.client.ui.remove(div)
root.unmount()
return {
unmount: () => {
game.client.ui.remove(div)
root.unmount()
},
}
}

0 comments on commit d961a15

Please sign in to comment.