Skip to content

Instantly share code, notes, and snippets.

import { useQuery } from '@tanstack/react-query'
import { Category } from '@/model/category'
import * as CategoryApi from '@/utils/axios/category'
export default function useCategoryFetcher(categoryId?: string) {
const { data, refetch, isLoading, error } = useQuery<
Category[] | Category,
Error
>({
queryKey: ['category', categoryId],
@nixjs
nixjs / react-providers-tree.tsx
Created March 26, 2025 00:39
Build providers tree in react
import { ComponentType, ReactNode, FC } from 'react';
type ProviderWithProps<P = any> = [ComponentType<P>, P?];
const buildProvidersTree = <P extends ProviderWithProps[]>(
providers: [...P]
): FC<{ children: ReactNode }> => {
return ({ children }) =>
providers.reduceRight<ReactNode>((acc, [Provider, props]) => {
return props ? (
@nixjs
nixjs / i18n.d.ts
Last active March 23, 2025 01:24
Use i18n CDN for next app router
export const locales = ['en', 'vi'] as const;
export interface Messages {
welcome: string;
[key: string]: string | object;
}
declare module 'next-intl' {
interface AppConfig {
Locale: (typeof locales)[number];
@nixjs
nixjs / demo-controlled.tsx
Created March 22, 2025 04:40
Multi level dropdown
"use client"
import { useState } from "react"
import { MultiLevelDropdown, type MenuItem } from "./multi-level-dropdown-controlled"
// Sample data structure
const locationData: MenuItem = {
id: "root",
label: "Location",
children: [
@nixjs
nixjs / .npmrc
Last active March 18, 2025 08:54
//gitlab.com/api/v4/projects/[[number]]/packages/npm/:_authToken=${NPM_TOKEN}
@package:registry=https://gitlab.com/api/v4/projects/[[number]]/packages/npm/
strict-peer-dependencies=false
legacy-peer-deps=true
auto-install-peers=true
node-linker=hoisted
{
"locales": [
{"key": "aa", "value": "Afar"},
{"key": "ab", "value": "Abkhaz"},
{"key": "ae", "value": "Avestan"},
{"key": "af", "value": "Afrikaans"},
{"key": "ak", "value": "Akan"},
{"key": "am", "value": "Amharic"},
{"key": "an", "value": "Aragonese"},
{"key": "ar", "value": "Arabic"},

To create a virtual environment, go to your project’s directory and run the following command. This will create a new virtual environment in a local folder named .venv:

python3 -m venv .venv

Activate a virtual environment

source .venv/bin/activate

To confirm the virtual environment is activated, check the location of your Python interpreter:

{
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
@nixjs
nixjs / MultiLevelDropdown.tsx
Created March 3, 2025 02:48
Multi level dropdown
"use client"
import { useState, useRef, useEffect } from "react"
import { ChevronLeft, ChevronRight, Menu } from "lucide-react"
const locationData: MenuItem = {
id: 'root',
label: 'Location',
children: [
{
@nixjs
nixjs / code.md
Created September 7, 2024 04:25
Changing file extensions for all files in a directory on OS X

If you're using the zsh shell

autoload -U zmv
zmv '(**/)(*).txt' '$1$2.md'