Skip to content

Commit

Permalink
Merge pull request #53 from pete-murphy/pm/add-flush-sync
Browse files Browse the repository at this point in the history
Add flushSync
  • Loading branch information
i-am-the-slime committed Jul 11, 2023
2 parents 12cc426 + 5480bcf commit b93b156
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit b93b156

Please sign in to comment.