Skip to content

Commit 5480bcf

Browse files
committed
Add flushSync
1 parent 12cc426 commit 5480bcf

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/React/Basic/DOM.js

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ export function unmount(node) {
1919
export function createPortal(jsx) {
2020
return (node) => ReactDOM.createPortal(jsx, node);
2121
}
22+
23+
export function flushSync(callback) {
24+
return () => ReactDOM.flushSync(callback);
25+
}

src/React/Basic/DOM.purs

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module React.Basic.DOM
1313
, unmount
1414
, createPortal
1515
, text
16+
, flushSync
1617
, module Generated
1718
) where
1819

@@ -100,4 +101,15 @@ foreign import createPortal :: JSX -> Element -> JSX
100101

101102
-- | Create a text node.
102103
text :: String -> JSX
103-
text = unsafeCoerce
104+
text = unsafeCoerce
105+
106+
-- | `flushSync` lets you force React to flush any updates inside the provided
107+
-- | callback synchronously. This ensures that the DOM is updated immediately.
108+
-- |
109+
-- | ```purs
110+
-- | let
111+
-- | handleNewChatMessage msg = do
112+
-- | flushSync (setMessages (_ <> [msg]))
113+
-- | scrollToLastMessage
114+
-- | ```
115+
foreign import flushSync :: forall a. Effect a -> Effect a

0 commit comments

Comments
 (0)