Skip to content

Instantly share code, notes, and snippets.

View horaciosystem's full-sized avatar
🏠
Working from home

Horacio Alexandre Fernandes horaciosystem

🏠
Working from home
View GitHub Profile
import { useCallback, useEffect, useRef } from 'react';
import { debounce } from 'lodash';
import { FormikValues } from 'formik';
import { FormikConfig } from 'formik/dist/types';
export function useDebouncedValidate<T extends FormikValues>({
values,
validate,
debounceTime = 200,
}: {
@reimertz
reimertz / 1.rxjs-firestore.js
Last active May 3, 2023 02:57
RxJS + Firestore + React hooks basics
import { Observable, combineLatest } from 'rxjs'
import { startWith } from 'rxjs/operators'
import { useEffect, useState } from 'react'
export const docData = doc => {
const data = doc.data()
const idKey = data && data.id ? 'firebaseId' : 'id' // if original data contains an id..
return {
...data,
@sibelius
sibelius / createQueryRendererSuspense.tsx
Created September 25, 2019 15:40
createQueryRendererSuspense helper to make it easy add ErrorBoundaryWithRetry and Suspense handling
export const createQueryRendererSuspense = (Component: React.ComponentType<any>) => {
const QueryRendererWrapper = props => {
return (
<ErrorBoundaryWithRetry fallback={(error, retry) => <ErrorView error={error} retry={retry} />}>
<React.Suspense fallback={<LoadingView />}>
<Component {...props} />
</React.Suspense>
</ErrorBoundaryWithRetry>
);
};
@max10rogerio
max10rogerio / yup.locale.pt-br.js
Last active May 10, 2024 17:02
Translation of the main messages from the Yup library into the Pt-Br language.
/* eslint-disable */
// For more infos, see: https://github.com/jquense/yup/blob/master/src/locale.js
import { setLocale } from 'yup'
const translation = {
mixed: {
default: '${path} é inválido',
required: '${path} é um campo obrigatório',
oneOf: '${path} deve ser um dos seguintes valores: ${values}',
notOneOf: '${path} não pode ser um dos seguintes valores: ${values}',
@kettanaito
kettanaito / client-App.jsx
Last active April 21, 2023 22:16
React - SSR (Server-side rendering)
// Root of the actual application.
// Feel free to branch from here, create routes and any other things
// rendered on both browser and server.
//
// Don't use modules relying on "window" here, as it would throw on the serfver.
// If using any such logic, move it to "client-index" instead, as its being rendered
// in the browser only.
import React from 'react'
const App = () => (
@dferber90
dferber90 / visual-regression-testing.md
Last active July 2, 2023 08:45
Visual Regression Testing in Jest

Visual Regression Testing with Jest

This is a walkthrough of how to set up Visual Regression Testing with Jest for an application created with create-react-app.

The following walkthrough uses React as an example, but the approach should work for any modern frontend library! I assume it can be used with Angular, Vue, Cycle.js and more.

This gist walks you through a create-react-app application as an example of how to set up Visual Regression Testing in Jest using libraries I wrote recently which enable this: jsdom-screenshot, jest-transform-css and jest-transform-file.

@laurenfazah
laurenfazah / express_postgress_knex.md
Last active November 26, 2022 13:19
Cheat Sheet: Setting up Express with Postgres via Knex

Express & Postgres via Knex

Note: <example> is meant to denote text replaced by you (including brackets).

Setup

// global dependencies
npm install -g knex
@fokusferit
fokusferit / enzyme_render_diffs.md
Last active June 18, 2024 11:27
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@yajra
yajra / axios-401-response-interceptor.js
Last active October 8, 2024 21:22
Axios 401 response interceptor.
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@m3kh66
m3kh66 / account-spec.js
Created March 12, 2016 20:16
How to test a request protected with express.js csurf and supertest?
'use strict';
var request = require('supertest');
var jsdom = require('jsdom');
var app = require('../../app');
describe('account middleware', () => {
var server;