|
|
@@ -3,8 +3,7 @@ import {
|
|
|
createContext,
|
|
|
type Dispatch,
|
|
|
useContext,
|
|
|
- useReducer,
|
|
|
- useEffect
|
|
|
+ useReducer
|
|
|
} from "react";
|
|
|
import {
|
|
|
type ConfigType
|
|
|
@@ -85,26 +84,25 @@ class NCoreContext<T extends {} | undefined, K extends ConfigType<T>> {
|
|
|
}) => {
|
|
|
const StateContextRenderer = this.stateContext;
|
|
|
|
|
|
- const [state, setState]: [T, Dispatch<Partial<T>>] = useReducer((state: T, nextState: Partial<T>) => {
|
|
|
- const newState = {
|
|
|
- ...state,
|
|
|
- ...nextState
|
|
|
- };
|
|
|
+ const [state,
|
|
|
+ setState]: [T, Dispatch<Partial<T>>] = useReducer((state: T, nextState: Partial<T>) => {
|
|
|
+ const newState = {
|
|
|
+ ...state,
|
|
|
+ ...nextState
|
|
|
+ };
|
|
|
|
|
|
- this.state = newState;
|
|
|
+ this.state = newState;
|
|
|
|
|
|
- this.emit(undefined, this.state);
|
|
|
+ this.emit(undefined, this.state);
|
|
|
|
|
|
- if(this.config.isSaveState && this.config.onStorageUpdate) {
|
|
|
- this.config.onStorageUpdate(this.state);
|
|
|
- }
|
|
|
+ if(this.config.isSaveState && this.config.onStorageUpdate) {
|
|
|
+ this.config.onStorageUpdate(this.state);
|
|
|
+ }
|
|
|
|
|
|
- return newState;
|
|
|
- }, this.state);
|
|
|
+ return newState;
|
|
|
+ }, this.state);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- this.setState = setState;
|
|
|
- }, []);
|
|
|
+ this.setState = setState;
|
|
|
|
|
|
return <StateContextRenderer.Provider
|
|
|
value={state}
|