Skip to content

Instantly share code, notes, and snippets.

View mateussmohamed's full-sized avatar
🤘

Mateus Santana mateussmohamed

🤘
View GitHub Profile
@KristofferEriksson
KristofferEriksson / useLocalStorage.ts
Last active March 21, 2024 20:31
An easy-to-use API for storing and retrieving data from Local Storage in React, with built-in real-time synchronization
import { useEffect, useState } from "react";
function useLocalStorage() {
const [loadingStates, setLoadingStates] = useState<Map<string, boolean>>(
new Map()
);
const setStorageValue = <T>(key: string, value: T) => {
try {
window.localStorage.setItem(key, JSON.stringify(value));
@sibelius
sibelius / testingConcept.md
Last active February 1, 2024 17:36
testing library concept and basic test

You first need to undestand the concept of frontend tests.

You should not test the implementation but the behavior

You test like the end user

For instance, imagine a login screen with email and password inputs and a submit button

The test should input the email and the password, then click in the submit button.

@jgcmarins
jgcmarins / changelog.js
Created November 9, 2020 17:10
Setup to generate git tag and GitHub release with changelog based on commit messages
#!/bin/env node
// @ts-check
import fs from 'fs';
import { exec as execCb } from 'child_process';
import util from 'util';
import moment from 'moment';
import git from 'simple-git/promise';
@sibelius
sibelius / useStateCallback.tsx
Last active July 29, 2020 13:42
useState that properly handles a function value
export const useStateCallback = (callback: Function) => {
const [value, setValue] = useState(() => callback);
const setCallback = useCallback((fn: Function) => {
setValue(() => fn);
}, [setValue]
return [value, setCallback];
}
@sibelius
sibelius / FeatureFlag.tsx
Created May 6, 2020 12:33
Basic Feature Flag implementation using React.Context
import React, { useContext, useCallback } from 'react';
export const FeatureFlagContext = React.createContext<string[]>([]);
export const useFeatureFlag = () => {
const features = useContext<string[]>(FeatureFlagContext);
const hasFeature = useCallback(
(feature: string) => {
return features.includes(feature);
@alexandrebodin
alexandrebodin / App.js
Created January 23, 2020 20:46
Strapi graphQL upload mutation
import React from "react";
import "./App.css";
import { ApolloProvider } from "@apollo/react-hooks";
import gql from "graphql-tag";
import { ApolloClient } from "apollo-client";
import { createUploadLink } from "apollo-upload-client";
import { InMemoryCache } from "apollo-cache-inmemory";
@felisio
felisio / array_iteration_thoughts_pt-BR.md
Last active May 31, 2024 20:59 — forked from ljharb/array_iteration_thoughts.md
Métodos de iteração de Array

Métodos de iteração de Array

Adaptação do fork: (https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff)

Ao tentar explicar como o Javascript usa seu métodos para arrays, acabei reunindo esses conceitos. Espero que Seja util. Ficarei feliz com qualquer sugestão.

Introdução

O Objet Array no Javascript tem muitos métodos construidos no seu prototype. Alguns deles modificam o proprio array passado. Felizmente, a maioria não, eles retonar um novo array inteiramente distinto. Uma vez que arrays são conceitualmente uma lista de itens, ajuda na clareza do código e sua manutenção a ponto de ser capas de operar de uma forma mais "funcional" . (Eu insisto em refrenciar um array como uma "Lista" - embora em algumas linguaguens de programação, Lista é um tipo de dado nativo, mais em JS e nesse POST, estou me referindo ao conceito. Em todos os lugares que eu usar a palavra "lista" você pode assumir que eu estou falando de JS Array) Isso siginifica, para a execução de uma simples operação na Lista como um

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a