- Instalar TypeScript y demás dependencias
npm i -D typescript @types/node ts-node-dev rimraf
- Inicializar el archivo de configuración de TypeScript ( Se puede configurar al gusto)
npx tsc --init --outDir dist/ --rootDir src
.table-container { | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
margin-top: 20px; | |
} | |
.table { | |
width: 100%; | |
max-width: 90vw; |
export const timeSince = ( date: string ) => { | |
const baseDate = new Date(date) | |
const seconds = Math.floor(( new Date().getTime() - baseDate.getTime() ) / 1000); | |
let interval = seconds / 31536000; |
import React, { PropsWithChildren } from "react"; | |
import { renderHook, RenderOptions } from "@testing-library/react"; | |
import { Provider } from "react-redux"; | |
import { ToolkitStore } from "@reduxjs/toolkit/dist/configureStore"; | |
import type { AppStore } from "../../src/store"; | |
// This type interface extends the default options for render from RTL, as well | |
// as allows the user to specify other things such as store. | |
interface ExtendedRenderOptions extends Omit<RenderOptions, "queries"> { | |
store?: AppStore; |
import { render, RenderOptions } from '@testing-library/react'; | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { store } from '../../store'; | |
const Providers: React.FC = ({ children }) => { | |
return ( | |
<Provider store={store}> | |
{children} | |
</Provider> |
export const getEnvironments = () => {
import.meta.env;
return {
...import.meta.env,
};
import { useState, ChangeEvent, useEffect, useMemo } from "react"; | |
export const useForm = <T extends Object>( | |
initialForm: T, | |
formValidations: { | |
[key: string]: [(value: string) => boolean, string]; | |
} = {} | |
) => { | |
const [formState, setFormState] = useState(initialForm); | |
const [formValidation, setFormValidation] = useState( |
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; | |
export const todosApi = createApi({ | |
reducerPath: "todos", | |
baseQuery: fetchBaseQuery({ | |
baseUrl: "https://jsonplaceholder.typicode.com", | |
}), | |
endpoints: (builder) => ({ | |
getTodos: builder.query({ | |
query: () => "/todos", |
import { createSlice } from "@reduxjs/toolkit"; | |
import type { PayloadAction } from "@reduxjs/toolkit"; | |
export interface CounterState { | |
counter: number; | |
} | |
const initialState: CounterState = { | |
counter: 0, | |
}; |