Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flushSync to preact-compat #3094

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -127,6 +138,7 @@ export {
PureComponent,
memo,
forwardRef,
flushSync,
// eslint-disable-next-line camelcase
unstable_batchedUpdates,
StrictMode,
Expand Down Expand Up @@ -166,6 +178,7 @@ export default {
PureComponent,
memo,
forwardRef,
flushSync,
unstable_batchedUpdates,
StrictMode,
Suspense,
Expand Down