Skip to content

Instantly share code, notes, and snippets.

@hnngo
hnngo / pre-commit-eslint
Created November 25, 2019 11:01 — forked from shettayyy/pre-commit-eslint
Pre-commit hook for Linting JS with ESLint before commit.
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$")
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
import React, { useState, useCallback } from 'react';
import Button from './Button';
const Example = () => {
const [count, setCount] = useState(0);
const increment = useCallback(() => {
setCount(c => c + 1);
}, [setCount]);
@hnngo
hnngo / 06-react-useContext.js
Created August 7, 2019 05:21
react-insight
import React, { useContext } from 'react';
const currentPath = React.createContext({ path: '/welcome' });
const goNext = React.createContext(true);
const isLogin = React.createContext(false);
const Section = () => {
const path = useContext(currentPath);
return (
@hnngo
hnngo / 05-react-custom-hook.js
Created August 2, 2019 05:41
react-insight
const useColor = (color) => {
useEffect(() => {
document.title = color;
}, [color]);
};
const Section = () => {
const [color, setColor] = useState("red");
const handleSelectColor = (e) => {
@hnngo
hnngo / 04-react-fragment.js
Created August 1, 2019 05:23
react-insight
render() {
return (
<React.Fragment>
<ChildA />
<ChildB />
<ChildC />
</React.Fragment>
);
}
const ProfileComponent = React.lazy(() => import('./ProfileComponent'));
const PortfolioComponent = React.lazy(() => import('./PortfolioComponent'));
function InfoComponent() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<section>
<ProfileComponent />
<PortfolioComponent />
@hnngo
hnngo / 02-react-memo.js
Created July 30, 2019 12:30
react-insight
import React, { useState } from 'react';
function MyComponent(props) {
return (
<div>
<p>Name: {props.input.name}</p>
</div>
)
}
@hnngo
hnngo / 01-pure-component.js
Last active July 30, 2019 06:43
react-insight
import React from 'react';
class PureComponent extends React.PureComponent {
render() {
return (
<div>
<p>Name: {this.props.input.name}</p>
</div>
);
}
@hnngo
hnngo / README-Template.md
Created July 24, 2019 06:13 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites