-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jason Healy
committed
Jan 24, 2020
1 parent
19236cd
commit 06ff655
Showing
6 changed files
with
121 additions
and
232 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useState, createContext } from 'react' | ||
|
||
export const AppContext = createContext<AppState | any>({}) | ||
|
||
interface AppState { | ||
defaultDid: string | ||
} | ||
|
||
export const AppProvider = (props: any) => { | ||
const defaultDid = localStorage.getItem('defaultId') || '' | ||
|
||
const [appState, setGlobalState] = useState<AppState>({ | ||
defaultDid: defaultDid, | ||
}) | ||
|
||
const setDefaultDid = (did: string) => { | ||
localStorage.setItem('defaultId', did) | ||
|
||
const newState = { | ||
...appState, | ||
defaultDid: did, | ||
} | ||
|
||
setGlobalState(newState) | ||
} | ||
|
||
return <AppContext.Provider value={[appState, setDefaultDid]}>{props.children}</AppContext.Provider> | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.