Skip to content

Instantly share code, notes, and snippets.

View phucdph's full-sized avatar
🎯
Focusing

Phuc Dang phucdph

🎯
Focusing
View GitHub Profile
This file has been truncated, but you can view the full file.
#!/usr/bin/env node
'use strict';
var require$$0$5 = require('os');
var require$$1$3 = require('fs');
var require$$2$2 = require('url');
var require$$3$2 = require('path');
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
const fs = require("fs");
const path = require("path");
const { minimatch } = require("minimatch");
// Function to parse CODEOWNERS file
function parseCodeowners(codeownersFile) {
const rules = [];
const lines = fs.readFileSync(codeownersFile, "utf-8").split("\n");
lines.forEach((line) => {
@phucdph
phucdph / useWhyDidUpdate.ts
Created April 13, 2020 03:24
[Hook] useWhyDidUpdate
const useWhyDidYouUpdate = (name: string, props: any) => {
const previousProps = useRef<any>({});
useEffect(() => {
if (previousProps.current) {
const allKeys = Object.keys({
...(previousProps.current || {}),
...props
});
const changesObj = {} as any;
@phucdph
phucdph / MaterialUIForm.tsx
Created April 4, 2020 16:08
[Formik] Material UI Form
const MaterialForm = () => {
const handleSubmit = React.useCallback((values: IFormValues, actions) => {
signUp(values);
actions.setSubmitting(false);
}, []);
return (
<Formik<IFormValues>
initialValues={{
@phucdph
phucdph / TextField.tsx
Created April 4, 2020 16:04
[Formik] Custom Field
import { FieldAttributes } from "formik";
import * as React from "react";
import { get } from "lodash";
import { TextField as BaseTextField } from "@material-ui/core";
interface IProps extends FieldAttributes<any> {}
const TextField = (props: IProps) => {
const { field, form, ...rest } = props;
@phucdph
phucdph / BasicForm.tsx
Last active April 4, 2020 15:26
[Formik] Complete Form
import * as React from "react";
import { Formik, Form, FastField, ErrorMessage } from "formik";
import * as Yup from "yup";
interface IProps {}
interface IFormValues {
username: string;
name: string;
email: string;
@phucdph
phucdph / BasicForm.tsx
Created April 4, 2020 15:05
[Formik] Async validation
const isUsernameValid = (username: string): Promise<boolean> =>
new Promise(resolve => {
const fakeUsernames = ["phuchoang2710", "abc123"];
setTimeout(() => {
resolve(fakeUsernames.indexOf(username) < 0);
}, 1000);
});
const validationSchema = Yup.object().shape<IFormValues>({
name: Yup.string().required("Please enter your name"),
@phucdph
phucdph / BasicForm.tsx
Created April 4, 2020 14:49
[Formik] Validation Schema
const validationSchema = Yup.object().shape<IFormValues>({
name: Yup.string().required("Please enter your name"),
email: Yup.string()
.email("Please enter valid email")
.required("Please enter your email"),
username: Yup.string()
.required("Please enter username")
.min(5, "Your username is too short")
.max(30, "Your username is too long"),
password: Yup.string()
@phucdph
phucdph / BasicForm.tsx
Created April 4, 2020 14:27
[Formik] Full Field
const BasicForm = () => {
const handleSubmit = React.useCallback((values: IFormValues) => {
console.log(values);
}, []);
return (
<Formik<IFormValues>
initialValues={{
username: "",
name: "",
@phucdph
phucdph / BasicForm.tsx
Created April 4, 2020 14:16
[Formik] Input with Field
const BasicForm = () => {
const handleSubmit = React.useCallback((values: IFormValues) => {
console.log(values);
}, []);
return (
<Formik<IFormValues>
initialValues={{
username: "",
name: "",