This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a session storage instance | |
let sessionStorage = createCookieSessionStorage(); | |
// create authenticator instance | |
let authenticator = new Authenticator<User>( | |
sessionStorage | |
); | |
// configure the authenticator to use the Auth0 strategy for sign-in | |
authenticator.use( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { randomBytes } from 'crypto'; | |
import * as React from 'react'; | |
import { Request, Session } from 'remix'; | |
import { parseBody, parseParams } from './parse-body'; | |
/** | |
* An error that is thrown when a CSRF token is missing or invalid. | |
* @example | |
* throw new InvalidAuthenticityToken("Can't verify CSRF token authenticity."); | |
* @example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Serializer { | |
abstract attributes: string[]; | |
[customAttribute: string]: unknown; // this allow this[attribute] to work so we can use getters to add extra attributes | |
constructor(protected input: Record<string, unknown>) {} | |
private filterAttributes() { | |
return Object.fromEntries( | |
this.attributes.map((attribute) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ms from "ms"; | |
import * as React from "react"; | |
import { useQuery } from "react-query"; | |
import { hasOwn } from "../utils"; | |
let isProduction = process.env.NODE_ENV === "production"; | |
export interface Translations { | |
[key: string]: string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useMutation, UseMutationOptions } from "react-query"; | |
import { pluralize, singularize } from "inflected"; | |
import { generatePath } from "react-router-dom"; | |
type Config<Input, Output, Error> = { | |
/** | |
* Any React Query option for useMutation | |
* @type {UseMutationOptions<Output, APIError<Error>, Input>} | |
*/ | |
options?: UseMutationOptions<Output, APIError<Error>, Input>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, ReactNode, FormEventHandler } from "react"; | |
import { MutationResultPair, MutateConfig, QueryStatus } from "react-query"; | |
import * as yup from "yup"; | |
function noop() {} | |
type FormProps<Data> = { | |
action: MutationResultPair<Data, Error, FormData, never | (() => void)>; | |
children(status: QueryStatus): ReactNode; | |
validation: yup.ObjectSchema; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useQuery, QueryConfig } from "react-query"; | |
type ID = string | number; | |
type Resource = { name: string; id: ID }; | |
class APIClientError extends Error {} | |
class APIServerError extends Error {} | |
export async function getEntity<Entity = unknown>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Si tenemos este HTML | |
* <section id="some-section"> | |
* <article> <h2>Article 1</h2> <article>A nested one</article> </article> | |
* <article> <h2>Article 2</h2> <article>A nested one</article> </article> | |
* <article> <h2>Article 3</h2> <article>A nested one</article> </article> | |
* </section> | |
*/ | |
const section = document.querySelector("#some-section"); | |
// Haciendo esto obtenemos seis artículos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyComponent(props) { | |
// refs | |
const $item = React.useRef(); | |
// states | |
const [value, setValue] = React.useState(""); | |
// computed | |
const filtered = React.useMemo( | |
() => props.list.filter((item) => item.includes(value)), | |
[props.list, value] | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
const FeatureFlags = React.createContext(null); | |
export function FeatureProvider({ features = null, children }) { | |
if (features === null || typeof features !== "object") { | |
throw new TypeError("The features prop must be an object or an array."); | |
} | |
return ( | |
<FeatureFlags.Provider value={features}>{children}</FeatureFlags.Provider> |