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

chore: replace the deprecated react type definition #3382

Merged
merged 2 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/brown-camels-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"mobx-react": minor
"mobx-react-lite": minor
---

replace the deprecated react type definition with recommended type definition
8 changes: 4 additions & 4 deletions packages/mobx-react-lite/src/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IObserverOptions {
}

export function observer<P extends object, TRef = {}>(
baseComponent: React.RefForwardingComponent<TRef, P>,
baseComponent: React.ForwardRefRenderFunction<TRef, P>,
options: IObserverOptions & { forwardRef: true }
): React.MemoExoticComponent<
React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<TRef>>
Expand All @@ -40,13 +40,13 @@ export function observer<P extends object>(
): React.FunctionComponent<P>

export function observer<
C extends React.FunctionComponent<any> | React.RefForwardingComponent<any>,
C extends React.FunctionComponent<any> | React.ForwardRefRenderFunction<any>,
Options extends IObserverOptions
>(
baseComponent: C,
options?: Options
): Options extends { forwardRef: true }
? C extends React.RefForwardingComponent<infer TRef, infer P>
? C extends React.ForwardRefRenderFunction<infer TRef, infer P>
? C &
React.MemoExoticComponent<
React.ForwardRefExoticComponent<
Expand All @@ -59,7 +59,7 @@ export function observer<
// n.b. base case is not used for actual typings or exported in the typing files
export function observer<P extends object, TRef = {}>(
baseComponent:
| React.RefForwardingComponent<TRef, P>
| React.ForwardRefRenderFunction<TRef, P>
| React.FunctionComponent<P>
| React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<TRef>>,
// TODO remove in next major
Expand Down
5 changes: 4 additions & 1 deletion packages/mobx-react/src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ function getInjectName(component: IReactComponent<any>, injectNames: string): st

function grabStoresByName(
storeNames: Array<string>
): (baseStores: IValueMap, nextProps: React.Props<any>) => React.PropsWithRef<any> | undefined {
): (
baseStores: IValueMap,
nextProps: React.ClassAttributes<any>
) => React.PropsWithRef<any> | undefined {
return function (baseStores, nextProps) {
storeNames.forEach(function (storeName) {
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx-react/src/observerClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function makeComponentReactive(render: any) {
return reactiveRender.call(this)
}

function observerSCU(nextProps: React.Props<any>, nextState: any): boolean {
function observerSCU(nextProps: React.ClassAttributes<any>, nextState: any): boolean {
if (isUsingStaticRendering()) {
console.warn(
"[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side."
Expand Down