From e8812dcada2310f3e9bc2ffdcc74ffa47428841e Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Tue, 30 Mar 2021 22:55:03 -0400 Subject: [PATCH] Add flushSync to preact-compat --- compat/src/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compat/src/index.js b/compat/src/index.js index e0c907361e..2fa033cdab 100644 --- a/compat/src/index.js +++ b/compat/src/index.js @@ -101,6 +101,17 @@ function findDOMNode(component) { // eslint-disable-next-line camelcase const unstable_batchedUpdates = (callback, arg) => callback(arg); +/** + * In React, `flushSync` flushes the entire tree and forces a rerender. It's + * implmented here as a no-op. + * @template Arg + * @template Result + * @param {(arg: Arg) => Result} callback function that runs before the flush + * @param {Arg} [arg] Optional arugment that can be passed to the callback + * @returns + */ +const flushSync = (callback, arg) => callback(arg) + /** * Strict Mode is not implemented in Preact, so we provide a stand-in for it * that just renders its children without imposing any restrictions. @@ -127,6 +138,7 @@ export { PureComponent, memo, forwardRef, + flushSync, // eslint-disable-next-line camelcase unstable_batchedUpdates, StrictMode, @@ -166,6 +178,7 @@ export default { PureComponent, memo, forwardRef, + flushSync, unstable_batchedUpdates, StrictMode, Suspense,