Skip to content

Commit 6caa523

Browse files
committed
Add flushSync
1 parent 12cc426 commit 6caa523

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-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

+12-1
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@ foreign import createPortal :: JSX -> Element -> JSX
100100

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

0 commit comments

Comments
 (0)