Skip to content

Instantly share code, notes, and snippets.

View mistical2008's full-sized avatar

Evgeniy Talko mistical2008

  • Russia
View GitHub Profile
@mistical2008
mistical2008 / .__init.md
Created February 19, 2022 10:18 — forked from rickyalmeidadev/.__init.md
vite + react + @swc/jest
yarn create vite
@mistical2008
mistical2008 / cachified.ts
Created December 9, 2021 13:43 — forked from kentcdodds/cachified.ts
Turn any function into a cachified one. With forceFresh support and value checking (for when the data type changes). This uses redis, but you could change it to use whatever you want.
type CacheMetadata = {
createdTime: number
maxAge: number | null
expires: number | null
}
function shouldRefresh(metadata: CacheMetadata) {
if (metadata.maxAge) {
return Date.now() > metadata.createdTime + metadata.maxAge
}
@mistical2008
mistical2008 / session.server.ts
Created December 9, 2021 13:42 — forked from kentcdodds/session.server.ts
Authentication in Remix applications
import * as bcrypt from "bcrypt";
import { createCookieSessionStorage, redirect } from "remix";
import { db } from "./db.server";
export type LoginForm = {
username: string;
password: string;
};
@mistical2008
mistical2008 / cell.tsx
Created December 9, 2021 13:42 — forked from kentcdodds/cell.tsx
A real-world example of the prop getters pattern
function Cell({
value,
row: {values: user},
column: {id: propertyName},
}: {
value: string
row: {values: User}
column: {id: string}
}) {
@mistical2008
mistical2008 / scroll-restoration.tsx
Created December 9, 2021 13:41 — forked from kentcdodds/scroll-restoration.tsx
scroll-restoration.tsx
import * as React from 'react'
import {useLocation} from 'react-router-dom'
import {useTransition} from '@remix-run/react'
import {useBeforeUnload} from 'remix'
import {useSSRLayoutEffect} from './misc'
let firstRender = true
let positions: {[key: string]: number} = {}
const SESSION_STORAGE_KEY = 'kody_scroll_positions'
import React from "react";
import { Link } from "react-router-dom";
export function createResource(getPromise) {
let cache = {};
let inflight = {};
let errors = {};
function load(key) {
inflight[key] = getPromise(key)
import { Machine, assign } from "xstate";
import firebase from "./firebase";
const chart = {
id: "auth",
context: {
auth: null,
error: null,
loggedoutTime: null
},
import React from "react";
import { renderToNodeStream } from "react-dom/server";
import Remix, { loadRouteData } from "remix/RemixNode";
// same App as entry-web!
import App from "./App";
export default async (req, res, assets, matches) => {
// @remix-run/firebase is calling this function and passing
// the arguments in, @remix-run/aws or @remix-run/azure will
// pass in whatever APIs those platforms use
// you have total control over the server rendering, here we
import React from "react";
import { Meta, Scripts, Styles, Routes } from "@remix-run/react";
import { useLocation } from "react-router-dom";
let noScriptPaths = new Set(["/", "/buy", "/logout", "/features", "/privacy"]);
export default function App() {
let location = useLocation()
let includeScripts = !noScriptPaths.has(location.pathname);
let { lang }= useLocalization()
import type { Action, Loader } from "@remix-run/loader";
import { json, parseFormBody, redirect } from "@remix-run/loader";
import { readTodos, createTodo, deleteTodo } from "../data/todo";
let action: Action = async ({ request, context: { session } }) => {
let [method, body] = await methodOverride(request);
await new Promise((res) => setTimeout(res, 1000));
switch (method) {
case "post": {
let [_, error] = await createTodo(body!.name);