use-context-selector
Advanced tools
Comparing version 2.0.0-alpha.2 to 2.0.0-alpha.3
@@ -1,2 +0,8 @@ | ||
import { Context } from 'react'; | ||
import { ComponentType } from 'react'; | ||
export interface Context<Value> { | ||
Provider: ComponentType<{ | ||
value: Value; | ||
}>; | ||
displayName?: string; | ||
} | ||
/** | ||
@@ -3,0 +9,0 @@ * This creates a special context for selector-enabled `useContext`. |
{ | ||
"name": "use-context-selector", | ||
"description": "React useContext with selector support in userland", | ||
"version": "2.0.0-alpha.2", | ||
"version": "2.0.0-alpha.3", | ||
"publishConfig": { | ||
@@ -6,0 +6,0 @@ "tag": "next" |
@@ -182,3 +182,3 @@ # use-context-selector | ||
- The [stale props](https://react-redux.js.org/api/hooks#stale-props-and-zombie-children) issue isn't solved. | ||
- Due to the current useMutableSource limitation, a selector can't return a function. (See `02_basic_spec` wrapping setState) | ||
- Due to the current useMutableSource limitation, a selector can't return a function. (See `01_basic_spec` wrapping setState) | ||
- Tearing is only avoided within the Provider tree. A value outside the Provider will tear. (`02_tearing_spec` fails) | ||
@@ -185,0 +185,0 @@ |
/* eslint-disable @typescript-eslint/ban-ts-ignore */ | ||
import { | ||
Context, | ||
ComponentType, | ||
Context as ContextOrig, | ||
FC, | ||
@@ -44,2 +45,7 @@ MutableRefObject, | ||
export interface Context<Value> { | ||
Provider: ComponentType<{ value: Value }>; | ||
displayName?: string; | ||
} | ||
const createProvider = <Value>(ProviderOrig: Provider<ContextValue<Value>>) => { | ||
@@ -81,10 +87,6 @@ const RefProvider: FC<{ value: Value }> = ({ value, children }) => { | ||
const source = createMutableSource({ current: defaultValue }, () => defaultValue); | ||
const context = createContextOrig( | ||
{ [SOURCE_SYMBOL]: source }, | ||
) as unknown as Context<Value>; // HACK typing | ||
context.Provider = createProvider( | ||
context.Provider as unknown as Provider<ContextValue<Value>>, // HACK typing | ||
) as Provider<Value>; | ||
const context = createContextOrig({ [SOURCE_SYMBOL]: source }); | ||
(context as unknown as Context<Value>).Provider = createProvider(context.Provider); | ||
delete context.Consumer; // no support for Consumer | ||
return context; | ||
return context as unknown as Context<Value>; | ||
} | ||
@@ -127,4 +129,4 @@ | ||
const { [SOURCE_SYMBOL]: source } = useContextOrig( | ||
context, | ||
) as unknown as ContextValue<Value>; // HACK typing | ||
context as unknown as ContextOrig<ContextValue<Value>>, | ||
); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -131,0 +133,0 @@ if (!source) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40570
203