From 58b360595624a0a7b6949dc2ce21e3d55f61c6c6 Mon Sep 17 00:00:00 2001 From: Jordan Thomson Date: Wed, 11 Dec 2024 14:48:25 +1100 Subject: [PATCH] added warning for legacy context types in function components --- packages/mobx-react-lite/src/observer.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/mobx-react-lite/src/observer.ts b/packages/mobx-react-lite/src/observer.ts index 9baf579ff..2f4a79928 100644 --- a/packages/mobx-react-lite/src/observer.ts +++ b/packages/mobx-react-lite/src/observer.ts @@ -4,6 +4,7 @@ import { isUsingStaticRendering } from "./staticRendering" import { useObserver } from "./useObserver" let warnObserverOptionsDeprecated = true +let warnLegacyContextTypes = true const hasSymbol = typeof Symbol === "function" && Symbol.for const isFunctionNameConfigurable = @@ -137,6 +138,13 @@ export function observer

( ;(observerComponent as React.FunctionComponent).contextTypes = ( baseComponent as any ).contextTypes + + if (process.env.NODE_ENV !== "production" && warnLegacyContextTypes) { + warnLegacyContextTypes = false + console.warn( + `[mobx-react-lite] Support for Legacy Context in function components will be removed in the next major release.` + ) + } } if (useForwardRef) {