From 5480bcf853bd551afbfb65db724b9ab8db3beba5 Mon Sep 17 00:00:00 2001 From: Peter Murphy <26548438+ptrfrncsmrph@users.noreply.github.com> Date: Thu, 18 May 2023 14:21:49 -0400 Subject: [PATCH] Add flushSync --- src/React/Basic/DOM.js | 4 ++++ src/React/Basic/DOM.purs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/React/Basic/DOM.js b/src/React/Basic/DOM.js index de26467..257f887 100644 --- a/src/React/Basic/DOM.js +++ b/src/React/Basic/DOM.js @@ -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); +} diff --git a/src/React/Basic/DOM.purs b/src/React/Basic/DOM.purs index fc20ffb..0acb058 100644 --- a/src/React/Basic/DOM.purs +++ b/src/React/Basic/DOM.purs @@ -13,6 +13,7 @@ module React.Basic.DOM , unmount , createPortal , text + , flushSync , module Generated ) where @@ -100,4 +101,15 @@ foreign import createPortal :: JSX -> Element -> JSX -- | Create a text node. text :: String -> JSX -text = unsafeCoerce \ No newline at end of file +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
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: