Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add flushSync
  • Loading branch information
pete-murphy committed May 18, 2023
commit 5480bcf853bd551afbfb65db724b9ab8db3beba5
4 changes: 4 additions & 0 deletions src/React/Basic/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ export function unmount(node) {
export function createPortal(jsx) {
return (node) => ReactDOM.createPortal(jsx, node);
}

export function flushSync(callback) {
return () => ReactDOM.flushSync(callback);
}
14 changes: 13 additions & 1 deletion src/React/Basic/DOM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module React.Basic.DOM
, unmount
, createPortal
, text
, flushSync
, module Generated
) where

Expand Down Expand Up @@ -100,4 +101,15 @@ foreign import createPortal :: JSX -> Element -> JSX

-- | Create a text node.
text :: String -> JSX
text = unsafeCoerce
text = unsafeCoerce

-- | `flushSync` lets you force React to flush any updates inside the provided
-- | callback synchronously. This ensures that the DOM is updated immediately.
-- |
-- | ```purs
-- | let
-- | handleNewChatMessage msg = do
-- | flushSync (setMessages (_ <> [msg]))
-- | scrollToLastMessage
-- | ```
foreign import flushSync :: forall a. Effect a -> Effect a