Skip to content

Instantly share code, notes, and snippets.

View paulodutra's full-sized avatar

Paulo Dutra paulodutra

View GitHub Profile
@paulodutra
paulodutra / Checkbox-InlineChangeFunction.tsx
Created August 18, 2023 13:18
An example of checkbox component using the inline onChange function to set value
import React from 'react'
export const Checkbox = ({ label} : {label: string}) => {
const [value, setValue] = React.useState(false);
return (
<label style={{
padding: "1rem",
border: value ? "2px solid #8D2" : "2px solid #F70"
}}>
<input
@paulodutra
paulodutra / App.tsx
Created August 23, 2023 12:44
Example of component that use the input and checkbox component
import React from 'react';
import { Button } from './Button';
import { Input } from './Input';
import { Checkbox } from './Checkbox';
function App() {
const [total, setTotal] = React.useState(0)
const [data, setData] = React.useState('');
function increment() {
@paulodutra
paulodutra / App.tsx
Created August 23, 2023 13:32
Example using useState with parameter to other component - 1/2
import React, { useEffect } from 'react';
import { Button } from './Button';
function App() {
const [total, setTotal] = React.useState(0);
return (
<div>
<p>Total: {total}</p>
<Button increment={setTotal} />
</div>
@paulodutra
paulodutra / Button.tsx
Created August 23, 2023 13:33
Example using useState with parameter to other component - 2/2
import React from 'react'
type ButtonProps = {
increment: React.Dispatch<React.SetStateAction<number>>
}
export const Button = ({increment }: ButtonProps) => {
return <button onClick={() => increment((number) => number + 1)}>Increment</button>
}
@paulodutra
paulodutra / exports module
Last active August 2, 2024 18:23
Ways of exports and imports modules using CommonJS
First way, object using module.exports
module.exports = {
sum: function(a,b){
return a + b;
},
sub: function(a,b){
return a - b;
}
@paulodutra
paulodutra / tsconfig.json
Last active August 11, 2024 16:43
alias import tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
@paulodutra
paulodutra / jest.config.ts
Last active August 11, 2024 16:46
Module name mapper jest
module.exports = {
preset: 'ts-jest',
moduleFileExtensions: ['js', 'json', 'ts', 'node'],
rootDir: 'src',
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
@paulodutra
paulodutra / jest-e2e.json
Last active August 11, 2024 16:49
moduleNameMapper jest test e2e
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "../",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1",
@paulodutra
paulodutra / docker-compose.yaml
Last active August 11, 2024 16:50
docker-compose mysql container
version: '3.8'
services:
mysql:
image: mysql:8.0
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: nestjs_testing
MYSQL_USER: user
MYSQL_PASSWORD: user
@paulodutra
paulodutra / in-memory-database-config.ts
Last active August 11, 2024 16:54
InMemory database config Typeorm Nestjs
import { registerAs } from '@nestjs/config';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
export const inMemoryDatabaseConfig = registerAs(
'database.inMemory',
(): TypeOrmModuleOptions => ({
type: 'sqlite',
database: ':memory',
entities: [
__dirname +