Оптимизировал добавление плюс настроил реактивность для списка
This commit is contained in:
parent
3c76c7dc09
commit
b7fef53ad7
@ -1,5 +1,5 @@
|
||||
import {useState, useEffect} from 'react'
|
||||
import {cleanToken, grabToken, grabTokens, selectToken, storeToken} from "../functions/token";
|
||||
import {cleanToken, grabToken, grabTokenData, grabTokens, selectToken, storeToken} from "../functions/token";
|
||||
|
||||
export class Token {
|
||||
id!: string
|
||||
@ -39,9 +39,18 @@ export function useToken(): UseTokenInterface {
|
||||
setToken(grabToken()?.payload)
|
||||
}
|
||||
|
||||
const addToken = (token: string) => {
|
||||
const addToken = (token: string): boolean => {
|
||||
if (!grabTokenData(token)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
storeToken(token)
|
||||
setToken(grabToken()?.payload)
|
||||
setTokens([
|
||||
...tokens,
|
||||
grabToken()?.payload
|
||||
])
|
||||
return true
|
||||
}
|
||||
|
||||
return {token, tokens, switchToken, deleteToken, addToken}
|
||||
|
Loading…
Reference in New Issue
Block a user