-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
4f169ff
commit 5cffc19
Showing
4 changed files
with
32 additions
and
19 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
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,4 @@ | ||
import { TransferContext } from "@/providers/transfer-provider"; | ||
import { useContext } from "react"; | ||
|
||
export const useTransfer = () => useContext(TransferContext); |
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 |
---|---|---|
@@ -1,37 +1,21 @@ | ||
"use client"; | ||
|
||
import { TransferValue } from "@/components/transfer-input"; | ||
import { Dispatch, PropsWithChildren, SetStateAction, createContext, useState } from "react"; | ||
|
||
interface AppCtx { | ||
recordsSearch: string; | ||
transferValue: TransferValue; | ||
|
||
setRecordsSearch: Dispatch<SetStateAction<string>>; | ||
setTransferValue: Dispatch<SetStateAction<TransferValue>>; | ||
} | ||
|
||
const defaultValue: AppCtx = { | ||
recordsSearch: "", | ||
transferValue: { value: "", formatted: 0n }, | ||
|
||
setRecordsSearch: () => undefined, | ||
setTransferValue: () => undefined, | ||
}; | ||
|
||
export const AppContext = createContext(defaultValue); | ||
|
||
export default function AppProvider({ children }: PropsWithChildren<unknown>) { | ||
const [recordsSearch, setRecordsSearch] = useState(defaultValue.recordsSearch); | ||
|
||
/** | ||
* Why we define here: https://react.dev/reference/react/useDeferredValue#caveats | ||
*/ | ||
const [transferValue, setTransferValue] = useState(defaultValue.transferValue); | ||
|
||
return ( | ||
<AppContext.Provider value={{ recordsSearch, transferValue, setRecordsSearch, setTransferValue }}> | ||
{children} | ||
</AppContext.Provider> | ||
); | ||
return <AppContext.Provider value={{ recordsSearch, setRecordsSearch }}>{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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { TransferValue } from "@/components/transfer-input"; | ||
import { Dispatch, PropsWithChildren, SetStateAction, createContext, useState } from "react"; | ||
|
||
interface TransferCtx { | ||
transferValue: TransferValue; | ||
setTransferValue: Dispatch<SetStateAction<TransferValue>>; | ||
} | ||
|
||
const defaultValue: TransferCtx = { | ||
transferValue: { value: "", formatted: 0n }, | ||
setTransferValue: () => undefined, | ||
}; | ||
|
||
export const TransferContext = createContext(defaultValue); | ||
|
||
export default function TransferProvider({ children }: PropsWithChildren<unknown>) { | ||
/** | ||
* Why we define here: https://react.dev/reference/react/useDeferredValue#caveats | ||
*/ | ||
const [transferValue, setTransferValue] = useState(defaultValue.transferValue); | ||
|
||
return <TransferContext.Provider value={{ transferValue, setTransferValue }}>{children}</TransferContext.Provider>; | ||
} |