Skip to content

Instantly share code, notes, and snippets.

View IcodeNet's full-sized avatar
😀

Byron Thanopoulos IcodeNet

😀
View GitHub Profile
@LauraBeatris
LauraBeatris / styledComponentWithProps.ts
Last active October 30, 2023 11:47
Helper TS function to provide props for a Styled Component
function styledComponentWithProps<T, U extends HTMLElement = HTMLElement>
(styledFunction: StyledFunction<React.HTMLProps<U>>): StyledFunction<T & React.HTMLProps<U>> {
return styledFunction
}
@LauraBeatris
LauraBeatris / SocketContainer.jsx
Created July 21, 2020 16:08
React Phoenix Socket Context
import React, { useEffect, useMemo } from "react";
import { Socket } from "phoenix";
// A utility to get the JWT token of the user
import getUserJWT from "utils/getUserJWT";
// The URL of the socket, example: ws://localhost:4000
import { SOCKET_URL } from "settings/socket";
// A hook that returns the current user authenticated
@LauraBeatris
LauraBeatris / dateFns.ts
Created June 13, 2020 14:38
Internacionalization setup for React with i18n and date-fns
import * as dateFnsLocales from 'date-fns/locale';
import { Locale } from 'date-fns';
import i18n from './i18n';
interface Locales {
[key: string]: Locale;
}
const getDateFnsLocale = (): Locale => {
@denieler
denieler / data-test-id
Last active March 17, 2021 17:45
Data Test ID
Old test:
cy.visit('/email_messages')
cy.contains(FROM_EMAIL).click()
cy.findByRole('button', { name: 'Associate user' }).click()
cy.findByPlaceholderText('Type user name...').type(USER_NAME)
cy.findByRole('option', { name: new RegExp(USER_NAME) }).click()
cy.findByRole('button', { name: 'Select' }).click()
@BuonOmo
BuonOmo / aws-dynamo-db-delete-all-items.zsh
Last active September 8, 2023 15:07
Delete all items in a dynamo db table
#!/usr/bin/env zsh
# I'm using jq to parse json. I really suggest using it.
# I'm using parallel for faster results, you could use xargs or a for loop if you don't have parallel.
main() (
set -eux
local options="--profile some-profile"
local key='id'
local table='table'
@LauraBeatris
LauraBeatris / Spinner.js
Created April 16, 2020 21:59
Roullete Spinner made with React Hooks
const spinWheel = useCallback(() => {
// Receives the winner prop and search for his position in the spinner bets array
const order = [8, 1, 14, 2, 13, 3, 12, 4, 0, 11, 5, 10, 6, 9, 7];
const position = order.indexOf(winner);
// Determine position where to land
const rows = 12;
const card = 80 + 2 * 2;
let landingPosition = rows * 15 * card + position * card;
@LauraBeatris
LauraBeatris / react_redux.test.js
Last active October 30, 2023 11:48
Jest mocks for React Redux
import { useSelector, useDispatch } from 'react-redux'
import { render, fireEvent } from '@testing-library/react';
// It can receive two more parameters, the second one is to specify a factory instead of the jest's automocking feature
jest.mock('react-redux')
it('should load some items in the component', () => {
// Returning a mock data from the store to test the behavior of the component
useSelector.mockImplementation((cb) => cb({items: ['Hello World']})
@LauraBeatris
LauraBeatris / react-i18next.js
Last active October 30, 2023 11:48
Mock for react-i18next tests
const React = require('react');
const reactI18next = require('react-i18next');
/*
Also, if you're changing the language, add that mock function before your test suit
jest.mock('react-i18next', () => ({
useTranslation: () => ({
t: key => key,
i18n: { changeLanguage: jest.fn() },
@LauraBeatris
LauraBeatris / tests_utils.js
Created April 6, 2020 15:29
Wrapper of the render method of React Testing Library with Providers
import React from 'react';
import { render } from '@testing-library/react';
import { ThemeProvider } from 'styled-components';
import { MemoryRouter } from 'react-router-dom';
import theme from '~/styles/theme';
// eslint-disable-next-line
function ProvidersWrapper({ children }) {
return (
@stolinski
stolinski / Example.tsx
Last active June 8, 2022 05:54
Route Transitions with Framer Motion
const FakeComponent = () => {
return (
<AnimatedRoutes exitBeforeEnter initial={false}>
<RouteTransition exact path="/some-route">
<NewUsers />
</RouteTransition>
<RouteTransition exact path="/yo" >
<Users />
</RouteTransition>
</AnimatedRoutes>