Skip to content

Commit

Permalink
useEvent: Only check for calls during render in development (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Nov 3, 2022
1 parent 4e34e6e commit ef5ad1b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/toolpad-app/src/utils/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
let dispatcher: any = null;

function getCurrentDispatcher() {
// Only used to provide debug info during development.
// eslint-disable-next-line no-underscore-dangle
return (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher
.current;
Expand All @@ -29,8 +30,8 @@ export default function useEvent<F extends (...args: any[]) => void>(handler: F)
});
// @ts-expect-error
return React.useCallback((...args) => {
if (isInRender()) {
throw new Error('Cannot call event in Render!');
if (process.env.NODE_ENV !== 'production' && isInRender()) {
console.error(`Functions returned by useEvent can't be called during a React render.`);
}
const fn = ref.current;
fn(...args);
Expand Down

0 comments on commit ef5ad1b

Please sign in to comment.