From 9a6964d24503afe50a2c3412fd74dc92e4c3ad5c Mon Sep 17 00:00:00 2001 From: Doong Date: Wed, 24 Jul 2024 09:37:55 +0700 Subject: [PATCH] update connect --- package.json | 2 +- src/connect.js | 8 +++++--- src/hooks/useContextSelector.js | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9ca1cbd..c603d50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redext", - "version": "0.0.16-7", + "version": "0.0.17", "description": "A simple global store based on React Context and Hooks", "main": "./dist/index.js", "module": "./dist/esm/index.mjs", diff --git a/src/connect.js b/src/connect.js index 3d8c632..cb3405e 100644 --- a/src/connect.js +++ b/src/connect.js @@ -6,10 +6,12 @@ import useDispatcher from './hooks/useDispatcher'; const connect = (mapStateToProps, mapDispatchToProps) => Component => { return props => { const { dispatch } = useContext(Context); - - const memoState = useContextSelector(mapStateToProps); + + const memoState = useContextSelector(mapStateToProps, { + isWithSyncExternalStore: false + }); const dispatcher = useDispatcher(mapDispatchToProps); - + return ( { - if (useSyncExternalStore) { +const useContextSelector = (mapStateToProps, params = {}) => { + const { isWithSyncExternalStore = true } = params; + + if (isWithSyncExternalStore && useSyncExternalStore) { const { subscribe, getState } = useContext(Context); const getSnapshot = () => { if (!mapStateToProps) {