30 lines
656 B
TypeScript
30 lines
656 B
TypeScript
import { useContext } from "react";
|
|
import { BlacklistContext } from "./BlacklistProvider";
|
|
|
|
export function useBlacklist(publicKey : string) : [
|
|
boolean,
|
|
() => void,
|
|
() => void
|
|
] {
|
|
const context = useContext(BlacklistContext);
|
|
if(!context){
|
|
throw new Error("useBlacklist must be used within a BlacklistProvider");
|
|
}
|
|
|
|
const {isUserBlocked, blockUser, unblockUser} = context;
|
|
const blocked = isUserBlocked(publicKey);
|
|
|
|
const block = () => {
|
|
blockUser(publicKey);
|
|
}
|
|
|
|
const unblock = () => {
|
|
unblockUser(publicKey);
|
|
}
|
|
|
|
return [
|
|
blocked,
|
|
block,
|
|
unblock
|
|
]
|
|
} |