From 4900251b2189fb24226bb690fd9dadda462b15cf Mon Sep 17 00:00:00 2001 From: huangxuan Date: Thu, 30 Nov 2023 17:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/inula/src/inulax/adapters/reduxReact.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/inula/src/inulax/adapters/reduxReact.ts b/packages/inula/src/inulax/adapters/reduxReact.ts index 0f74af0c..32eff8d0 100644 --- a/packages/inula/src/inulax/adapters/reduxReact.ts +++ b/packages/inula/src/inulax/adapters/reduxReact.ts @@ -103,7 +103,7 @@ export function connect( dispatchProps, ownProps ): MergedProps => ({ ...stateProps, ...dispatchProps, ...ownProps } as unknown as MergedProps), - options: ConnectOption, + options?: ConnectOption ): Connector { if (!options) { options = {}; @@ -111,14 +111,13 @@ export function connect( //this component should bear the type returned from mapping functions return (Component: OriginalComponent): WrappedComponent => { - const useStore = createStoreHook(options.context || DefaultContext); + const useStore = createStoreHook(options?.context || DefaultContext); //this component should mimic original type of component used const Wrapper: WrappedComponent = (props: OwnProps) => { const store = useStore() as ReduxStoreHandler; const [state, setState] = useState(() => store.getState()); - useEffect(() => { const unsubscribe = store.subscribe(() => { setState(store.getState()); @@ -126,13 +125,13 @@ export function connect( return () => unsubscribe(); }, []); - const previous = useRef<{ state: { [key: string]: any }, mappedState: StateProps }>({ + const previous = useRef<{ state: { [key: string]: any }; mappedState: StateProps }>({ state: {}, mappedState: {} as StateProps, }); let mappedState: StateProps; - if (options.areStatesEqual) { + if (options?.areStatesEqual) { if (options.areStatesEqual(previous.current.state, state)) { mappedState = previous.current.mappedState as StateProps; } else { @@ -169,7 +168,7 @@ export function connect( return createElement(Component, mergedProps); }; - if (options.forwardRef) { + if (options?.forwardRef) { const forwarded = forwardRef((props, ref) => { return Wrapper({ ...props, ref: ref }); });