Skip to content

Instantly share code, notes, and snippets.

View adventureandre's full-sized avatar
💪
bora codar

Andre Luiz adventureandre

💪
bora codar
View GitHub Profile
@adventureandre
adventureandre / use-producerGlobal.ts
Created May 15, 2025 13:45
Uso global , estado global
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
type UseProducerGlobalType = {
producerId: string | null;
setProducer: (producer: string) => void;
clearProducer: () => void;
}
import { env } from "@/env"
export function api(path: string, init?: RequestInit) {
const token = localStorage.getItem('token')
const baseUrl = env.NEXT_PUBLIC_API_BASE_URL
const apiPrefix = ''
const url = new URL(apiPrefix.concat(path), baseUrl)
// Criar configuração com headers
@adventureandre
adventureandre / get-distance-between-coordinates.ts
Created October 28, 2024 00:49
Get distance between coordinates
export interface Coordinate {
latitude: number
longitude: number
}
export function getDistanceBetweenCoordinates(
from: Coordinate,
to: Coordinate,
) {
if (from.latitude === to.latitude && from.longitude === to.longitude) {
@adventureandre
adventureandre / page.tsx
Created September 11, 2024 02:28
Nextjs used generateMetadata
export async function generateMetadata({
params,
}: ProductProps): Promise<Metadata> {
return {
title: params.slug,
}
}
@adventureandre
adventureandre / IP.tsx
Created September 2, 2024 21:20
Recuparar ip do cliente
import { Suspense } from 'react'
import { headers } from 'next/headers'
function IP() {
const FALLBACK_IP_ADDRESS = '0.0.0.0'
const forwardedFor = headers().get('x-forwarded-for')
if (forwardedFor) {
return forwardedFor.split(',')[0] ?? FALLBACK_IP_ADDRESS
}
@adventureandre
adventureandre / Input.tsx
Last active August 5, 2024 01:03
Input Model Using Ref and Zod
import { forwardRef, InputHTMLAttributes, LegacyRef } from 'react'
import { FieldError } from 'react-hook-form'
import { Container, ErrorMessage, Input } from './style'
interface InputFormProps extends InputHTMLAttributes<HTMLInputElement> {
error?: FieldError
}
export const InputForm = forwardRef(function InputForm(
@adventureandre
adventureandre / loop.tsx
Last active July 18, 2024 00:08
React itens loop
{Array.from({ length: 4 }).map((_, i) => (
<div key={i} >{i}</div>
))}
@adventureandre
adventureandre / exempleofUsetheFormData.tsx
Created July 15, 2024 22:32
Exemple of Use the FormData
import { userStore } from '../../store/userStore'
export default function Home() {
async function handleUser(form: FormData) {
'use server'
const email = form.get('name') as string
if (!email) {
return
@adventureandre
adventureandre / cart-context.tsx
Created June 28, 2024 23:39
BaseContext Cart
import { ReactNode, createContext, useContext } from 'react'
interface CartContextType {}
const CartContext = createContext({} as CartContextType)
export function CartProvider({ children }: { children: ReactNode }) {
return <CartContext.Provider value={{}}>{children}</CartContext.Provider>
}
services:
# db mysql
db:
container_name: DB-
image: bitnami/mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: 12345
ports:
- "3306:3306"