Skip to content

Commit fb153ff

Browse files
committed
Update provider and Context
1 parent 5b5b47e commit fb153ff

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/components/Context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { React } from '../utils/react'
33
import type { Action, Store, UnknownAction } from 'redux'
44
import type { Subscription } from '../utils/Subscription'
55
import type { ProviderProps } from './Provider'
6+
import type { experimental } from 'react-concurrent-store'
67

78
export interface ReactReduxContextValue<
89
SS = any,
910
A extends Action<string> = UnknownAction,
1011
> extends Pick<ProviderProps, 'stabilityCheck' | 'identityFunctionCheck'> {
1112
store: Store<SS, A>
13+
reactStore: typeof experimental.Store<SS, A>
1214
subscription: Subscription
1315
getServerState?: () => SS
1416
}

src/components/Provider.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { createSubscription } from '../utils/Subscription'
66
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
77
import type { ReactReduxContextValue } from './Context'
88
import { ReactReduxContext } from './Context'
9+
import { experimental } from 'react-concurrent-store'
10+
const { StoreProvider } = experimental
11+
import type { ReactStore } from '../utils/reactStoreEnhancer'
912

1013
export interface ProviderProps<
1114
A extends Action<string> = UnknownAction,
@@ -59,11 +62,20 @@ function Provider<A extends Action<string> = UnknownAction, S = unknown>(
5962
) {
6063
const { children, context, serverState, store } = providerProps
6164

65+
// Validate store has reactStore
66+
if (!('reactStore' in store)) {
67+
throw new Error(
68+
'Redux store must be enhanced with addReactStore enhancer. ' +
69+
'Apply the enhancer when creating your store.',
70+
)
71+
}
72+
6273
const contextValue = React.useMemo(() => {
6374
const subscription = createSubscription(store)
6475

6576
const baseContextValue = {
6677
store,
78+
reactStore: store.reactStore as ReactStore,
6779
subscription,
6880
getServerState: serverState ? () => serverState : undefined,
6981
}
@@ -99,7 +111,11 @@ function Provider<A extends Action<string> = UnknownAction, S = unknown>(
99111

100112
const Context = context || ReactReduxContext
101113

102-
return <Context.Provider value={contextValue}>{children}</Context.Provider>
114+
return (
115+
<Context.Provider value={contextValue as any}>
116+
<StoreProvider>{children}</StoreProvider>
117+
</Context.Provider>
118+
)
103119
}
104120

105121
export default Provider

0 commit comments

Comments
 (0)