Skip to content

Commit

Permalink
update connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Doong committed Jul 24, 2024
1 parent 7375cc8 commit 9a6964d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 5 additions & 3 deletions src/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Component
{...props}
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useContextSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { useContext, useSyncExternalStore } from 'react';
import Context from '../Context';
import useDeepMemo from './useDeepMemo';

const useContextSelector = (mapStateToProps) => {
if (useSyncExternalStore) {
const useContextSelector = (mapStateToProps, params = {}) => {
const { isWithSyncExternalStore = true } = params;

if (isWithSyncExternalStore && useSyncExternalStore) {
const { subscribe, getState } = useContext(Context);
const getSnapshot = () => {
if (!mapStateToProps) {
Expand Down

0 comments on commit 9a6964d

Please sign in to comment.