Last active
June 24, 2021 13:08
-
-
Save tdeedlesATX/da316ccedf87b188be1b89795ea74314 to your computer and use it in GitHub Desktop.
layout customization hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {createContext, useContext, useReducer, useEffect} from 'react' | |
// presentation | |
import Layout from './Layout' | |
const LayoutContext = createContext(); | |
/** | |
* limits possible customizations | |
*/ | |
const layoutCustomizationReducer = (layoutState, action) => { | |
if (action.type === 'FAQ') { | |
return { | |
...state, | |
faq: payload | |
} | |
} | |
} | |
const useFaqLayoutCustomization = (faqData) => { | |
const [,dispatch] = useContext(); | |
useEffect(() => { dispatch({type: 'FAQ', payload: faqProps }) | |
} | |
const LayoutProvider = () => { | |
const useContext(LayoutContext); | |
const [state, dispatch] = useReducer(layoutCustomizationReducer); | |
<Provider value={/*...state (if needed),*/ dispatch}> | |
{/* state has "faq" prop */} | |
<Layout {...state}> | |
{children} | |
</Layout> | |
<Provider | |
} | |
// product engineer (building screens) toolkit | |
// probably should not affect much of layout, look-feel, perhaps just any data | |
// i.e. "what do the faq say?" rather than "how do the faq look?" | |
export {useFaqLayoutCustomization, /* use*LayoutCustomization */} | |
// boilerplate for app | |
export default LayoutProvider; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment