committed by
拾邑
2 changed files with 0 additions and 36 deletions
@ -1,20 +0,0 @@ |
|||||
import * as React from 'react'; |
|
||||
import { createContext, useContext, useReducer } from 'react'; |
|
||||
import uiReducer from '../reducer/ui'; |
|
||||
import { UIContext } from '../model'; |
|
||||
|
|
||||
interface ProviderProps { |
|
||||
children: React.ReactChild; |
|
||||
} |
|
||||
|
|
||||
const initialData = { formVisible: true, aaa: true }; |
|
||||
|
|
||||
const Context = createContext({ uiState: initialData } as UIContext); |
|
||||
|
|
||||
export const UIProvider = ({ children }: ProviderProps): JSX.Element => { |
|
||||
const [uiState, uiDispatch] = useReducer(uiReducer, initialData); |
|
||||
|
|
||||
return <Context.Provider value={{ uiState, uiDispatch }}>{children}</Context.Provider>; |
|
||||
}; |
|
||||
|
|
||||
export const useUI = (): UIContext => useContext(Context); |
|
@ -1,16 +0,0 @@ |
|||||
import { UIState, UIAction } from '../model'; |
|
||||
|
|
||||
const reducer = (state: UIState, action: UIAction): UIState => { |
|
||||
switch (action.type) { |
|
||||
case 'TOGGLE_FORM_VISIBLE': |
|
||||
return { formVisible: state.formVisible, aaa: false }; |
|
||||
case 'increment': |
|
||||
return state; |
|
||||
case 'decrement': |
|
||||
return state; |
|
||||
default: |
|
||||
return state; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
export default reducer; |
|
Loading…
Reference in new issue