Skip to content

Instantly share code, notes, and snippets.

@vasylnahuliak
vasylnahuliak / HCaptcha.tsx
Created January 24, 2025 15:53
Example of using usePromiseRef with WebView onMessage
import React, { FC, useImperativeHandle, useRef } from 'react';
import { Text, View, TouchableOpacity } from "react-native";
import ConfirmHcaptcha from '@hcaptcha/react-native-hcaptcha';
import type { WebViewMessageEvent } from 'react-native-webview';
import { isFunction, isString } from 'lodash';
import { usePromiseRef } from './usePromiseRef';
HCaptchaImperativeRefValue = {
@vasylnahuliak
vasylnahuliak / usePromiseRef.ts
Last active January 24, 2025 15:54
useRef with Promise
import { useRef, MutableRefObject } from 'react';
interface PromiseRef<T, E> {
promise: Promise<T>;
resolve: (value: T) => void;
reject: (reason: E) => void;
}
type UsePromiseRefReturn<T, E> = [
MutableRefObject<PromiseRef<T, E> | null>,
@vasylnahuliak
vasylnahuliak / Accordion.testID.ts
Created March 18, 2023 12:00
Example unique testID
import { getTestID } from 'helpers/getTestID/getTestID';
export const TEST_ID = {
CONTAINER: 'CONTAINER',
LABEL: 'LABEL',
};
export const testID = getTestID({
testID: TEST_ID,
prefix: 'ACCORDION',
@vasylnahuliak
vasylnahuliak / getTestID.ts
Last active June 23, 2023 05:42
Generating unique testID
type GetTestIDArgs<TestID> = {
testID: TestID;
prefix: string;
}
export const getTestID = <TestID extends Record<string, string>>({
testID,
prefix,
}: GetTestIDArgs<TestID>): TestID => {
return new Proxy(testID, {
@vasylnahuliak
vasylnahuliak / firebase_debug_view_ios.js
Created July 3, 2022 19:17
Firebase Debug View (iOS)
Settings.set({
'/google/firebase/debug_mode': 1,
'/google/measurement/debug_mode': 1,
});
@vasylnahuliak
vasylnahuliak / firebase_debug_view_android.sh
Created June 1, 2022 05:41
Firebase Debug View (Android)
adb shell setprop debug.firebase.analytics.app PACKAGE_NAME
import axios from 'axios';
const api = axios.create({
baseURL: process.env.API_URL,
timeout: 10000,
headers: {
'Content-Type': 'application/json',
},
});
console.log([...formData])
const data = new FormData();
Object.keys(payload).map(key => data.append(key, payload[key]));