mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Apply prettier over all files
This commit is contained in:
@@ -1,56 +1,56 @@
|
||||
import React, { FunctionComponent } from "react";
|
||||
import React, { FunctionComponent } from 'react'
|
||||
|
||||
export interface UIState {
|
||||
displaySidebar: boolean;
|
||||
openSidebar: () => {};
|
||||
closeSidebar: () => {};
|
||||
displaySidebar: boolean
|
||||
openSidebar: () => {}
|
||||
closeSidebar: () => {}
|
||||
}
|
||||
|
||||
const initialState = {
|
||||
displaySidebar: false,
|
||||
openSidebar: null,
|
||||
closeSidebar: null,
|
||||
};
|
||||
}
|
||||
|
||||
export const UIContext = React.createContext(initialState);
|
||||
UIContext.displayName = "UIContext";
|
||||
export const UIContext = React.createContext(initialState)
|
||||
UIContext.displayName = 'UIContext'
|
||||
|
||||
export const UIProvider: FunctionComponent = (props) => {
|
||||
const [state, dispatch] = React.useReducer(uiReducer, initialState);
|
||||
const [state, dispatch] = React.useReducer(uiReducer, initialState)
|
||||
|
||||
const openSidebar = () => dispatch("OPEN_SIDEBAR");
|
||||
const closeSidebar = () => dispatch("CLOSE_SIDEBAR");
|
||||
const openSidebar = () => dispatch('OPEN_SIDEBAR')
|
||||
const closeSidebar = () => dispatch('CLOSE_SIDEBAR')
|
||||
|
||||
const value = {
|
||||
...state,
|
||||
openSidebar,
|
||||
closeSidebar,
|
||||
};
|
||||
}
|
||||
|
||||
return <UIContext.Provider value={value} {...props} />;
|
||||
};
|
||||
return <UIContext.Provider value={value} {...props} />
|
||||
}
|
||||
|
||||
export const useUI = () => {
|
||||
const context = React.useContext(UIContext);
|
||||
const context = React.useContext(UIContext)
|
||||
if (context === undefined) {
|
||||
throw new Error(`useUI must be used within a UIProvider`);
|
||||
throw new Error(`useUI must be used within a UIProvider`)
|
||||
}
|
||||
return context;
|
||||
};
|
||||
return context
|
||||
}
|
||||
|
||||
function uiReducer(state, action) {
|
||||
switch (action) {
|
||||
case "OPEN_SIDEBAR": {
|
||||
case 'OPEN_SIDEBAR': {
|
||||
return {
|
||||
...state,
|
||||
displaySidebar: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
case "CLOSE_SIDEBAR": {
|
||||
case 'CLOSE_SIDEBAR': {
|
||||
return {
|
||||
...state,
|
||||
displaySidebar: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user