मुख्य सामग्री पर जाएं
स्निपेट·मुफ़्त

TypeScript के साथ React स्निपेट

.tsx फ़ाइलों के लिए 20 React स्निपेट: टाइप वाले props, useReducer ऐक्शन, क्लीनअप वाले effect, टाइप वाला context hook, useLocalStorage, एक error boundary और Testing Library टेस्ट। फ़ाइल को जो React import चाहिए, वे आप खुद जोड़ते हैं।

मुफ़्त में इंस्टॉल करें।

अगर आपके Android डिवाइस पर PocketCode इंस्टॉल है, तो यह पेज ऐप में खुलेगा।

प्रीव्यू

20 में से 5

Component with typed propstfc

Function component with a props type

type ${1:Button}Props = {
  ${2:label}: string;
  onClick?: () => void;
};

export function ${1:Button}({ ${2:label}, onClick }: ${1:Button}Props) {
  return <${3:button} onClick={onClick}>{${2:label}}</${3:button}>;
}

Component with childrentfcc

Wrapper component that renders its children

import type { ReactNode } from "react";

export function ${1:Card}({ children }: { children: ReactNode }) {
  return <div className="${2:card}">{children}</div>;
}

useState with a typeustate

State hook with an explicit type

const [${1:value}, set${2:Value}] = useState<${3:string}>(${4:""});

Reducer with typed actionsureducer

State and action types plus a reducer for useReducer

type ${1:State} = { ${2:count}: number };
type ${3:Action} = { type: "${4:increment}" } | { type: "${5:reset}" };

function ${6:reducer}(state: ${1:State}, action: ${3:Action}): ${1:State} {
  switch (action.type) {
    case "${4:increment}":
      return { ...state, ${2:count}: state.${2:count} + 1 };
    case "${5:reset}":
      return { ${2:count}: 0 };
  }
}

useEffect with cleanupueffect

Effect that undoes its work when the component unmounts or deps change

useEffect(() => {
  ${1:const id = setInterval(tick, 1000);}
  return () => {
    ${2:clearInterval(id);}
  };
}, [$3]);

1.0.0 में बदलाव

पहला संस्करण।

संबंधित

useDebounce हुक (React)मुफ़्तस्निपेटTypeScript में useDebounce और useDebouncedCallback, साथ में एक सर्च बॉक्स का उदाहरण। कंपोनेंट अनमाउंट होने पर दोनों अपना टाइमर साफ़ कर देते हैं।runCatching → Result<T, AppError>मुफ़्तस्निपेटTiny extension that lifts thrown exceptions into a typed Result<T, AppError>, so callers can pattern-match instead of try/catch.Kotlin और Android स्निपेटमुफ़्तस्निपेटAndroid ऐप्स के लिए 20 Kotlin स्निपेट: sealed UI स्टेट, StateFlow वाला Hilt ViewModel, कोरूटीन, Room एंटिटी और DAO, और Compose स्टेट व लिस्ट। किसी .kt फ़ाइल में uistate या hiltvm जैसा प्रीफ़िक्स लिखें।HTML और CSS स्निपेटमुफ़्तस्निपेट8 HTML स्निपेट (पेज लैंडमार्क, Open Graph टैग, picture, dialog, हेडर वाली टेबल) और 12 CSS स्निपेट (रीसेट, grid लेआउट, clamp, डार्क मोड वेरिएबल, कम मोशन, container query)।Rust स्निपेटमुफ़्तस्निपेट20 Rust स्निपेट जो एक serde struct को छोड़कर सिर्फ़ स्टैंडर्ड लाइब्रेरी इस्तेमाल करते हैं: From वाले एरर enum, iterator चेन, HashMap से गिनती, let else, Arc और Mutex के साथ थ्रेड, चैनल और एक टेस्ट मॉड्यूल।Bash स्निपेटमुफ़्तस्निपेटस्क्रिप्ट के लिए 20 Bash स्निपेट: सुरक्षित हेडर, आर्ग्युमेंट जाँच, getopts, फ़ाइलों और ऐरे पर लूप, trap से सफ़ाई, दोबारा कोशिश और कुछ git कमांड। किसी .sh फ़ाइल में प्रीफ़िक्स लिखें।