diff options
author | rohan09-raj <[email protected]> | 2022-08-17 16:37:42 +0530 |
---|---|---|
committer | rohan09-raj <[email protected]> | 2022-08-17 16:37:42 +0530 |
commit | 3e7f5cbd876b29c92fc1cda58aa54a9c591ef026 (patch) | |
tree | e5706d93708ae378e913a4d1737b0aec6c3b382d /client/src/context/User.js | |
parent | 1c9a3d21cc3479d299181d98fb895614e0aaf649 (diff) |
lol
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 +} |