Skip to content

Instantly share code, notes, and snippets.

View YussufElarif's full-sized avatar

Yussuf Elarif YussufElarif

  • London, UK
View GitHub Profile
import React, { createContext, useCallback, useContext, useMemo, useState } from "react";
import { useColorScheme } from "react-native";
import AsyncStorage from "@react-native-async-storage/async-storage"
import { dark, light } from "../../utls/layout";
const ThemeContext = createContext(undefined);
export default function ThemeContextProvider({ children }) {
const systemColorScheme = useColorScheme();
@YussufElarif
YussufElarif / useStorage.ts
Last active January 8, 2021 13:25
React useStorage localStorage hook
export function useStorage<T>(key: string)
{
function getKey()
{
const data = localStorage.getItem(key);
if (!data)
{
return;
}
@YussufElarif
YussufElarif / AuthRouteGuard.tsx
Last active December 31, 2020 21:42
AuthRouteGuard
import React from 'react';
import { useSelector } from 'react-redux';
import { Route, RouteProps, Redirect, useLocation } from 'react-router-dom';
import { useSearchParams } from 'hooks';
import { StatusEnum } from 'reducers/models';
import { Loader } from 'components/elements';
export function AppRoute({ component, secured, ...props }: (RouteProps & { secured?: boolean }))
{
import { useState, useEffect } from 'react';
export enum DeviceEnum
{
Desktop,
Tablet,
Mobile
}
export function useDevice()