diff options
author | Rohan Raj Gupta <[email protected]> | 2022-08-17 17:58:38 +0530 |
---|---|---|
committer | GitHub <[email protected]> | 2022-08-17 17:58:38 +0530 |
commit | fba27fbc54a39820fdf3cded36dbf0e40e882a42 (patch) | |
tree | b377e7b9c3e2e8507bed3f4a0c4f85a553d45b0b /client/src/context/User.js | |
parent | 90324f212b14b98096d10dfee8ea64eb0ef4bab6 (diff) | |
parent | 7a4411027293842b84c186ec737721572698c7d0 (diff) |
Merge pull request #6 from Blaster4385/develop
Fix this shit
Diffstat (limited to 'client/src/context/User.js')
-rw-r--r-- | client/src/context/User.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/client/src/context/User.js b/client/src/context/User.js new file mode 100644 index 0000000..fce7eda --- /dev/null +++ b/client/src/context/User.js @@ -0,0 +1,28 @@ +import React, { createContext, useState, useContext } from 'react' + +export const UserContext = createContext() + +export const Context = ({ children }) => { + const [aadhaarNumber, setAadhaarNumber] = useState(null) + const [userData, setUserData] = useState({}) + + const initialUser = { + aadhaarNumber, + setAadhaarNumber, + userData, + setUserData + } + + return ( + <UserContext.Provider value={initialUser}>{children}</UserContext.Provider> + ) +} + +export const userContext = () => { + const context = useContext(UserContext) + if (!context) { + throw new Error(`userContext context can only + be used in a component wrapped with UserContext`) + } + return context +} |