recoil#SetterOrUpdater TypeScript Examples
The following examples show how to use
recoil#SetterOrUpdater.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useRecoilStateDeferred.ts From nextclade with MIT License | 6 votes |
export function useRecoilStateDeferred<T>(recoilState: RecoilState<T>): [T, SetterOrUpdater<T>] {
const [initialValue, setRecoilValue] = useRecoilState_TRANSITION_SUPPORT_UNSTABLE(recoilState)
const [value, setValue] = useState(initialValue)
const [, startTransition] = useTransition()
const setValueDeferred = useCallback(
(valOrUpdater: ValOrUpdater<T>) => {
setValue(valOrUpdater)
startTransition(() => {
setRecoilValue(valOrUpdater)
})
},
[setRecoilValue],
)
return [value, setValueDeferred]
}
Example #2
Source File: accounts.ts From abrechnung with GNU Affero General Public License v3.0 | 5 votes |
addAccount = (account: Account, setAccounts: SetterOrUpdater<Array<Account>>) => {
setAccounts((currAccounts) => {
return [...currAccounts, account];
});
}
Example #3
Source File: accounts.ts From abrechnung with GNU Affero General Public License v3.0 | 5 votes |
updateAccount = (account: Account, setAccounts: SetterOrUpdater<Array<Account>>) => {
setAccounts((currAccounts) => {
return currAccounts.map((a) => (a.id === account.id ? account : a));
});
}
Example #4
Source File: transactions.ts From abrechnung with GNU Affero General Public License v3.0 | 5 votes |
addTransactionInState = (
transaction: TransactionBackend,
setTransactions: SetterOrUpdater<Array<TransactionBackend>>
) => {
setTransactions((currTransactions: Array<TransactionBackend>) => {
return [...currTransactions, transaction];
});
}
Example #5
Source File: transactions.ts From abrechnung with GNU Affero General Public License v3.0 | 5 votes |
updateTransactionInState = (
transaction: TransactionBackend,
setTransactions: SetterOrUpdater<Array<TransactionBackend>>
) => {
setTransactions((currTransactions: Array<TransactionBackend>) => {
return currTransactions.map((t) => (t.id === transaction.id ? transaction : t));
});
}