Skip to content

Instantly share code, notes, and snippets.

View anthowave's full-sized avatar
🏠
Working from home

anthowave

🏠
Working from home
View GitHub Profile
@anthowave
anthowave / README.md
Created August 22, 2020 08:32 — forked from iansu/README.md
Create React App 4.0 Alpha Testing

Create New App

JavaScript Template

npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

TypeScript Template

npx create-react-app@next --scripts-version=@next --template=typescript@next my-ts-app

@anthowave
anthowave / tools.md
Created August 16, 2020 14:46
useful tools for writing docs.

Package/library docs mostly come as static site.

Here are the list of useful SSGs(static site generator):

React

  • Next.js
  • Gatsby.js
  • React-static

Vue

@anthowave
anthowave / type.ts
Created August 9, 2020 14:08
TypeScript Challenge - define types with keys or values extracted from object
const COUNTRY_CODES = {
"US": "United of States",
"CA": "Canada",
"GB": "United Kingodm",
};
// type definition
type CountryCode = keyof typeof COUNTRY_CODES; // equivalent to: type CountryCode = "US" | "CA" | "GB";
type CountryName = typeof COUNTRY_CODES[CountryCode]; // equivalent to: type CountryName = "United of States" | "Canada" | "United Kingdom";
@anthowave
anthowave / FormSelect(TS).md
Created July 27, 2020 18:06
A demo project about building a custom FormSelect component using @react-hook-form
@anthowave
anthowave / 1.md
Created July 7, 2020 12:41 — forked from swyxio/1.md
Learn In Public - 7 opinions for your tech career

2019 update: this essay has been updated on my personal site, together with a followup on how to get started

2020 update: I'm now writing a book with updated versions of all these essays and 35 other chapters!!!!

1. Learn in public

If there's a golden rule, it's this one, so I put it first. All the other rules are more or less elaborations of this rule #1.

You already know that you will never be done learning. But most people "learn in private", and lurk. They consume content without creating any themselves. Again, that's fine, but we're here to talk about being in the top quintile. What you do here is to have a habit of creating learning exhaust. Write blogs and tutorials and cheatsheets. Speak at meetups and conferences. Ask and answer things on Stackoverflow or Reddit. (Avoid the walled gardens like Slack and Discourse, they're not public). Make Youtube videos

@anthowave
anthowave / usePagination.js
Created June 30, 2020 18:59
Pagination implementation using react-query. Thanks @tannerlinsley for this awesome library!
let [hasNextPage, setHasNextPage] = React.useState(true)
const { data } = useInfiniteQuery(key, (key, nextPage) => {
const data = fetch('/api?page=' + nextPage)
if (data.length) {
return data
} else {
setHasNextPage(false)
return []
@anthowave
anthowave / debounce.ts
Created June 29, 2020 12:12
a debounce utility in TypeScript
const debounce = <F extends (...args: any[]) => any>(
func: F,
waitFor: number,
) => {
let timeout: NodeJS.Timeout;
return (...args: Parameters<F>): Promise<ReturnType<F>> =>
new Promise((resolve) => {
if (timeout) {
clearTimeout(timeout);
@anthowave
anthowave / typescriptreact.json
Last active June 29, 2020 13:39
VS Code Snippet for ease of redux-saga request handlers
{
// Place your snippets for typescriptreact here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@anthowave
anthowave / react-input-search.ts
Last active November 29, 2022 09:33
This shows how to implement debounced search (interacting with API) in a custom input element
// Note: I write down only essential parts of the component, because the other part can make sense without itself.
import { useFilter } from 'hooks/useFilter.ts';
import debounce from 'lib/debounce';
function InputSearch({...} : InputSearchInterface) {
// api - a search api wrapper that returns promise
// useFilter - a custom react hook used for search (https://gist.github.com/anthowen/7309f9d54dcdeefcefab1e37a75d716c)
const [{ results, isSearching }, doFilter] = useFilter<T>(api, null, []);