Skip to content

createRoot (replacing render) #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
andys8 opened this issue Mar 30, 2022 · 3 comments
Open

createRoot (replacing render) #29

andys8 opened this issue Mar 30, 2022 · 3 comments
Labels
status: accepted This issue is now ready to be implemented via a PR. type: enhancement A new feature or addition.

Comments

@andys8
Copy link

andys8 commented Mar 30, 2022

React 18 was released. It encourages a switch from render to createRoot to benefit from the new implementation.

@andys8 andys8 changed the title createRoot createRoot (replacing render) Mar 30, 2022
@andys8
Copy link
Author

andys8 commented Apr 27, 2022

@andys8 andys8 closed this as completed Apr 27, 2022
@andys8 andys8 reopened this Apr 27, 2022
@thomashoneyman thomashoneyman added type: enhancement A new feature or addition. status: accepted This issue is now ready to be implemented via a PR. labels Apr 27, 2022
@andys8
Copy link
Author

andys8 commented Jul 6, 2022

@tellnobody1
Copy link

tellnobody1 commented Mar 31, 2023

"use strict"

import ReactDOMClient from "react-dom/client"

export const createRoot = container => () => ReactDOMClient.createRoot(container)
export const render = root => reactElement => () => root.render(reactElement)
import Effect (Effect)
import Prelude
import React (ReactElement)
import Web.DOM.Element (Element)

foreign import data Root :: Type
foreign import createRoot :: Element -> Effect Root
foreign import render :: Root -> ReactElement -> Effect Unit
import Data.Maybe (fromJust)
import Partial.Unsafe (unsafePartial)
import React (createLeafElement)
import Web.DOM.NonElementParentNode (getElementById)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.HTML.Window (document)

main :: Effect Unit
main = do
  doc <- window >>= document
  container <- getElementById "container" $ toNonElementParentNode doc
  root <- createRoot $ unsafePartial $ fromJust container
  render root $ createLeafElement appClass props
<div id="container"></div>
<script src="index.js"></script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted This issue is now ready to be implemented via a PR. type: enhancement A new feature or addition.
Development

No branches or pull requests

3 participants