diff options
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 +} |