Skip to content

Instantly share code, notes, and snippets.

View pupato13's full-sized avatar

Diego Pupato pupato13

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pupato13
pupato13 / authContext.tsx
Created April 15, 2021 20:04
Context + Reducer + Typescript
import React, {
createContext,
useCallback,
useContext,
useReducer,
} from "react";
import AsyncStorage from "@react-native-community/async-storage";
import api from "../services/api";
import { IAuthState, initialState } from "./authState";
import { ActionType, AuthActions, ICredentials } from "./authActions";
import createDataContext from "./createDataContext";
import trackerApi from "../api/trackerApi";
import AsyncStorage from "@react-native-community/async-storage";
import { navigate } from "../navigationRef";
const TOKEN_KEY = "@TrackersApp";
const ACTIONS = {
ADD_ERROR: "add_error",
SIGN_UP: "sign_up",
};
import { parse, format } from "date-fns";
export function convertStringToDate(dateValue: string): Date {
const parsedDate = parse(dateValue, "dd/MM/yyyy", new Date());
const day = parsedDate.getDate();
const month = parsedDate.getMonth();
const year = parsedDate.getFullYear();
return new Date(year, month, day, 23, 59, 59);
useEffect(() => {
const handleScroll = () => {
const currentScrollY = window.scrollY;
// Handle Menu Transparency
if (
currentScrollY > 50 &&
headerBackgroundColor === "transparent"
) {
setTransparentHeader(false);