Skip to content

Instantly share code, notes, and snippets.

View gist:6d857fe96228e04dbbd90631f5f3c38e
<button
mat-mini-fab
color="primary"
aria-label="minus"
(click)="setCounter(-1)"
[disabled]="isDisableMinus"
>
<mat-icon>remove</mat-icon>
</button>
View gist:3a9ced47b911ee1b25b3b48415080caf
export interface UserDto {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
View gist:82e165ede8b98583c6c3f9243b9a20e5
export const fetchUser = (key: string, user: string) =>
fetch(`https://api.github.com/users/${user}`).then((res) => res.json());
export default function usePost(user: string) {
return useQuery(user && ["user", user], fetchUser);
}
View gist:daeca49014a73984930879daf161b29d
<script async src="https://www.googletagmanager.com/gtag/js?id=code_analytics"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('config', 'code_analytics');
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=code_tag_manager"></script>
<script>
window.dataLayer = window.dataLayer || [];
View gist:a094f79731dddf5f46970d7ddd07cb54
const App = () => {
const [num, setNum] = useState(1);
useEffect(() => {
document.addEventListener("click", (ev) => {
setNum(Math.random());
});
return function cleanup() {
document.removeEventListener("click", (ev) => {});
};
}, [num]);
View gist:0cad17cb4bcb0884d9d34ecd8ae84ab3
interface IUserSchema extends Document {
about: string;
avatar: string;
email: string;
password: string;
status: boolean;
username: string;
following: IUserSchema[];
followers: IUserSchema[];
}
View gist:8f64ef96a398b83983c4f0c6a9288a86
const createRootReducer = (history: History) =>
combineReducers({
router: connectRouter(history),
auth: authReducer,
lang: langReducer,
});
nello slice
export const selectError = (state: { auth: AuthState }): boolean =>
View gist:e01f24bb427e62e665fe77e9cf02a29f
// Interceptor
const setupAxiosInterceptors = (onUnauthenticated: () => void) => {
const onRequestSuccess = (config: AxiosRequestConfig) => {
console.log("request success", config);
const token = Storage.local.get("auth");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
View gist:3eeb0eb76401f32dd032f3c55654e39f
export const authLoginEffects = (data: AuthLoginFormData) => (
dispatch: ThunkDispatch<{}, {}, AnyAction>
) => {
AuthService.login(data)
.then((data) => {
dispatch(authLoginSuccess(data));
Storage.local.set("auth", data);
dispatch(push("/user"));
})
.catch((_) => {
@whisher
whisher / gist:c8e0453a5fa76b5d6d952919c77ef0c4
Last active May 18, 2020
reactjs typescript useForm - a simple custom hook to manage form in react
View gist:c8e0453a5fa76b5d6d952919c77ef0c4
Credit to
https://medium.com/javascript-in-plain-english/react-controlled-forms-with-hooks-538762aab935
import React, { ChangeEvent, FormEvent, useReducer } from "react";
const useForm = (initialState: any) => {
const reducer = (
state: typeof initialState,
payload: { field: string; value: string }
) => {