The essential collection of React Snippets.
Only what you need and nothing more. No Redux. No React Native.
Simply, simple React snippets.
These snippets were selected carefully from my own day-to-day React use. Not everything in React is included here. This is a hand selected set of snippets that work the way that you would expect, not just a copy of the documentation.
Snippet | Renders |
---|---|
fc |
Function Component |
fcc |
Function Component With Children Props |
fcd |
Function Component With export Default |
fccd |
Function Component With Children Props and export Default |
clg |
log |
stater |
React.useState |
effectr |
React.useEffect |
callbackr |
React.useCallback |
memor |
React.useMemo |
state |
useState |
effect |
useEffect |
callback |
useCallback |
memo |
useMemo |
get |
get Request |
post |
post Request |
delete |
delete Request |
put |
put Request |
patch |
patch Request |
interface |Props {
}
const |: FunctionComponent<|Props> = () => {
return ( );
}
export default |;
import React,{FunctionComponent,PropsWithChildren} from 'react'
interface postPropsType extends PropsWithChildren {
|
}
export const post: FunctionComponent<postPropsType> = () => {
return ( <div>post</div> );
}
import React,{FunctionComponent} from 'react'
interface postPropsType {
|
}
const post: FunctionComponent<postPropsType> = () => {
return ( <div>post</div> );
}
export default post
import React, { FunctionComponent, PropsWithChildren } from "react";
interface postPropsType extends PropsWithChildren {}
const post: FunctionComponent<postPropsType> = () => {
return <div>post</div>;
};
export default post;
console.log(|)
const [, set] = React.useState();
React.useEffect(() => {}, []);
const | = React.useCallback(()=>{
},[])
const | = React.useMemo(()=>{
},[])
const [, set] = useState();
useEffect(() => {}, []);
const | = useCallback(()=>{
},[])
const | = useMemo(()=>{
},[])
import {AQHookTypeHelper, AQMethodTypeHelper, CreateApi} from "axiosQuery"
export type UseGET|Type = AQHookTypeHelper<{
method: AQMethodTypeHelper<"GET">
}>
export const useGET| = CreateApi<UseGET|Type>({
endPoint: () => ``,
name: () => [],
method: "GET",
})
import { AQHookTypeHelper, AQMethodTypeHelper, CreateApi } from "axiosQuery";
export type UsePOSTType = AQHookTypeHelper<{
method: AQMethodTypeHelper<"POST">,
}>;
export const usePOST =
CreateApi <
UsePOSTType >
{
endPoint: () => ``,
name: () => [],
method: "POST",
};
import {AQHookTypeHelper, AQMethodTypeHelper, CreateApi} from "axiosQuery"
export type UseDELETE|Type = AQHookTypeHelper<{
method: AQMethodTypeHelper<"DELETE">
}>
export const useDELETE| = CreateApi<UseDELETE|Type>({
endPoint: () => ``,
name: () => [],
method: "DELETE",
})
import { AQHookTypeHelper, AQMethodTypeHelper, CreateApi } from "axiosQuery";
export type UsePUTType = AQHookTypeHelper<{
method: AQMethodTypeHelper<"PUT">,
}>;
export const usePUT =
CreateApi <
UsePUTType >
{
endPoint: () => ``,
name: () => [],
method: "PUT",
};
import { AQHookTypeHelper, AQMethodTypeHelper, CreateApi } from "axiosQuery";
export type UsePATCHType = AQHookTypeHelper<{
method: AQMethodTypeHelper<"PATCH">,
}>;
export const usePATCH =
CreateApi <
UsePATCHType >
{
endPoint: () => ``,
name: () => [],
method: "PATCH",
};
While I wrote the initial version of this extension, many people (too many to name) have helped make it what it is today. From providing TypeScript definitions to keeping up with changing API and best practices. If you are enjoying this extension, you have the great React community to thank.