Оптимизировал добавление плюс настроил реактивность для списка

This commit is contained in:
Rinsvent 2023-04-08 23:25:17 +07:00
parent 3c76c7dc09
commit b7fef53ad7

View File

@ -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}