Last active
March 10, 2025 17:11
-
-
Save jasmo2/ac74666e76452e24e9cf552444227b88 to your computer and use it in GitHub Desktop.
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
// Example auth Context: https://dev.to/shareef/context-api-with-typescript-and-next-js-2m25 | |
import React, { createContext, useContext, useEffect, useState } from 'react'; | |
interface ElementContextType { | |
prop1?: string | any | |
} | |
export const ElementContext = createContext<ElementContextType>({ | |
prop1: 'default', | |
}); | |
export const useElementContext = () => useContext(ElementContext) | |
type Props = { | |
children: React.ReactNode; | |
}; | |
export const ElementProvider = (props: Props): JSX.Element => { | |
const [propState, setPropState] = useState<string | any>(); | |
/** | |
* use useEffect if require | |
*/ | |
return ( | |
<ElementContext.Provider value={{ propState }}> | |
{props.children} | |
</ElementContext.Provider> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment