React Snippets for VS Code
A comprehensive collection of React snippets for Visual Studio Code, including React 19 features.
⚠️ Disclaimer ⚠️
This extension is not an official React product. It is a third-party extension created to enhance the React development experience in VS Code.
Credits
Features
This extension provides snippets for:
- React 19 Features (useFormState, useFormStatus, useOptimistic, etc.)
- React Functional Components
- React Hooks (useState, useEffect, useCallback, useMemo, useRef, useContext, useReducer)
- React Context
- React Error Boundaries
- React Suspense
- React Lazy Loading
- React Portals
- TypeScript support for all React features
- Custom Hooks
- Event Handlers
- React HTML Elements
- React Fragments
- React Conditional Rendering
- React Inline Styles
- Redux Toolkit Integration
- And more!
Installation
- Open VS Code
- Press
Ctrl+P
to open the Quick Open dialog
- Type
ext install react-snippets
and press Enter
- Reload VS Code when prompted
Usage
Type the prefix of the snippet you want to use and press Tab
or Enter
to insert it.
Core React Snippets (JavaScript)
Prefix |
Description |
rfc |
React Functional Component |
rfcp |
React Functional Component with Props |
useState |
React useState Hook |
useEffect |
React useEffect Hook |
useCallback |
React useCallback Hook |
useMemo |
React useMemo Hook |
useRef |
React useRef Hook |
useContext |
React useContext Hook |
useReducer |
React useReducer Hook |
useCustom |
React Custom Hook |
errorBoundary |
React Error Boundary |
suspense |
React Suspense |
lazy |
React Lazy Loading |
memo |
React Memo |
portal |
React Portal |
context |
React Context |
useformstate |
React useFormState Hook |
useformstatus |
React useFormStatus Hook |
useoptimistic |
React useOptimistic Hook |
usetransition |
React useTransition Hook |
usedeferredvalue |
React useDeferredValue Hook |
useid |
React useId Hook |
usesyncexternalstore |
React useSyncExternalStore Hook |
useinsertioneffect |
React useInsertionEffect Hook |
Core React Snippets (TypeScript)
Prefix |
Description |
rfct |
React Functional Component with TypeScript |
useStateT |
React useState Hook with TypeScript |
useReducerT |
React useReducer Hook with TypeScript |
contextT |
React Context with TypeScript |
useCustomT |
React Custom Hook with TypeScript |
eventHandlerT |
React Event Handler with TypeScript |
useRefT |
React Ref with TypeScript |
propsT |
React Component Props Type |
stateT |
React Component State Type |
rxtslice |
React Redux Toolkit Slice |
useformstateT |
React useFormState Hook with TypeScript |
useformstatusT |
React useFormStatus Hook with TypeScript |
useoptimisticT |
React useOptimistic Hook with TypeScript |
usetransitionT |
React useTransition Hook with TypeScript |
usedeferredvalueT |
React useDeferredValue Hook with TypeScript |
useidT |
React useId Hook with TypeScript |
usesyncexternalstoreT |
React useSyncExternalStore Hook with TypeScript |
useinsertioneffectT |
React useInsertionEffect Hook with TypeScript |
React HTML Snippets (JavaScript)
Prefix |
Description |
rbutton |
React HTML Button |
rinput |
React HTML Input |
rform |
React HTML Form |
rselect |
React HTML Select |
rtextarea |
React HTML Textarea |
rlabel |
React HTML Label |
rimg |
React HTML Image |
rlink |
React HTML Link |
rdiv |
React HTML Div |
rspan |
React HTML Span |
rlist |
React HTML List |
rtable |
React HTML Table |
rfrag |
React Fragment |
rfragcontent |
React Fragment with Content |
rjsxattr |
React JSX Attribute |
rjsxcomp |
React Component JSX |
rinlineStyle |
React Inline Style |
rforminput |
React Form Input |
rcondrender |
React Conditional Render (Ternary) |
reventhandler |
React Event Handler |
rcondif |
React Conditional Render (If Statement) |
React HTML Snippets (TypeScript)
Prefix |
Description |
rbuttonT |
React HTML Button with TypeScript |
rinputT |
React HTML Input with TypeScript |
rformT |
React HTML Form with TypeScript |
rselectT |
React HTML Select with TypeScript |
rtextareaT |
React HTML Textarea with TypeScript |
rlabelT |
React HTML Label with TypeScript |
rimgT |
React HTML Image with TypeScript |
rlinkT |
React HTML Link with TypeScript |
rdivT |
React HTML Div with TypeScript |
rspanT |
React HTML Span with TypeScript |
rlistT |
React HTML List with TypeScript |
rtableT |
React HTML Table with TypeScript |
rfragT |
React Fragment with TypeScript |
rfragcontentT |
React Fragment with Content and TypeScript |
rjsxattrT |
React JSX Attribute with TypeScript |
rjsxcompT |
React Component JSX with TypeScript |
rinlineStyleT |
React Inline Style with TypeScript |
rforminputT |
React Form Input with TypeScript |
rcondrenderT |
React Conditional Render (Ternary) with TypeScript |
reventhandlerT |
React Event Handler with TypeScript |
rcondifT |
React Conditional Render (If Statement) with TypeScript |
Examples
React Functional Component
import React from 'react';
const MyComponent = () => {
return (
<div>
Hello World!
</div>
);
};
export default MyComponent;
React useState Hook
const [count, setCount] = useState(0);
React useEffect Hook
useEffect(() => {
// Effect code here
return () => {
// Cleanup code here
};
}, [dependencies]);
<button
type="button"
className="btn"
onClick={handleClick}
disabled={false}
>
Click Me
</button>
<input
type="text"
className="input"
value={value}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => handleChange(e)}
placeholder="Enter text..."
required={false}
/>
React Fragment
<>
<div>Content 1</div>
<div>Content 2</div>
</>
React Conditional Render
{isLoggedIn ? (
<UserProfile />
) : (
<LoginForm />
)}
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
interface CounterState {
value: number;
}
const initialState: CounterState = {
value: 0,
};
const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment: (state) => {
state.value += 1;
},
},
});
export const { increment } = counterSlice.actions;
export default counterSlice.reducer;
const [state, formAction] = useFormState(action, initialState);
const { pending, data, method, action } = useFormStatus();
React useOptimistic Hook
const [optimisticState, addOptimistic] = useOptimistic(state, (state, optimisticValue) => {
return { ...state, update: optimisticValue };
});
React useTransition Hook
const [isPending, startTransition] = useTransition();
const handleClick = () => {
startTransition(() => {
// Update state
});
};
Contributing
We welcome your feedback and suggestions to improve these snippets.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you find any issues or have suggestions, please contact the extension author.
Official Links
Acknowledgments
- Thanks to all who have helped make this extension better
- Inspired by the React community and best practices