Last active
          September 1, 2022 13:28 
        
      - 
      
 - 
        
Save chrisfosterelli/2e523b4beae43f05624920b26bb55fa0 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
chrisfosterelli revised this gist
Dec 17, 2021 . 2 changed files with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ function AccountProvider({ children }) { const [account, setAccount] = useState(null) return ( <AccountContext.Provider value={[ account, setAccount ]}> {children} </AccountContext.Provider> ) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ import React from 'react' import useAccount from '../hooks/useAccount' function MyComponent() { const [account, setAccount] = useAccount() return <div>{account ? account.firstName : 'No Account'}</div> } export default MyComponent  - 
        
chrisfosterelli created this gist
Dec 17, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ import { createContext } from 'react' export default createContext(null) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ import React, { useState } from 'react' import AccountContext from '../contexts/AccountContext' function AccountProvider({ children }) { const [account, setAccount] = useState(null) return ( <AccountContext.Provider value={{ account, setAccount }}> {children} </AccountContext.Provider> ) } AccountProvider.propTypes = { children: PropTypes.node.isRequired } export default AccountProvider 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ import React from 'react' import ReactDOM from 'react-dom' import App from './components/app/App' import AccountProvider from './providers/AccountProvider' ReactDOM.render( <AccountProvider> <App /> </AccountProvider>, document.getElementById('root') ) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ import { useContext } from 'react' import AccountContext from '../contexts/AccountContext' function useAccount() { const value = useContext(AccountContext) if (value === null) throw new Error('<AccountProvider> is not in the parent tree') return value } export default useAccount