Skip to content

Instantly share code, notes, and snippets.

@BoBeenLee
BoBeenLee / ErrorBoundary.tsx
Last active March 19, 2023 05:02
Popular Component And Hooks
import React, { Component } from 'react'
export interface ErrorBoundaryProps {
children: React.ReactNode;
fallback: React.ReactNode;
onError?: (error: Error, errorInfo: React.ErrorInfo) => void
}
export interface ErrorBoundaryStates {
error: Error | null;
@BoBeenLee
BoBeenLee / _document.tsx
Created February 12, 2023 12:51 — forked from kmvan/_document.tsx
Next 12 + React 18 _document.tsx
import Document, {
DocumentContext,
Head,
Html,
Main,
NextScript,
} from 'next/document'
import { CSSProperties, ServerStyleSheet } from 'styled-components'
import { AppContextProps } from 'YOUR APP CONTEXT'
interface PageDocumentProps {
export function buildDistanceInWordsLocale () {
// tslint:disable:object-literal-sort-keys
const distanceInWordsLocale:any = {
lessThanXSeconds: {
one: '방금 전',
other: '방금 전'
},
xSeconds: {
one: '방금 전',
import _ from "lodash";
import { AsyncStorage } from "react-native";
const setItem = (key: string, value: string) => {
return new Promise((resolve, reject) => {
AsyncStorage.multiSet([[key, value]], errors => {
if (_.isEmpty(errors)) {
resolve(true);
return;
}
@BoBeenLee
BoBeenLee / common.ts
Last active June 17, 2019 03:10
React And Typescript
export const getValue = <T>(func: () => T, defaultValue: T):T => {
try {
return func();
} catch {
return defaultValue;
}
}
export function delay(seconds: number = 500) {
return new Promise(
@BoBeenLee
BoBeenLee / MainActivity.java
Last active December 7, 2018 02:01
react native android webview setting
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
}
// make a function to handle that error
function handleError(fn) {
return function (...params) {
return fn(...params).catch(function (err) {
// do something with the error!
console.error('Opps!', err);
});
}
}
@BoBeenLee
BoBeenLee / createLazily.js
Created March 17, 2018 12:56
createLazily
function createLazily(msec = 1000) {
let ongoing;
return function* lazily(task, ...args) {
if (ongoing && ongoing.isRunning()) {
ongoing.cancel();
}
ongoing = yield fork(function* doTask() {
yield call(delay, msec);
yield fork(task, ...args);
});
@BoBeenLee
BoBeenLee / generic1.ts
Created March 11, 2018 05:15
generic typescript
interface Person {
name: string;
age: number;
}
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
function setProperty<T, K extends keyof T, V extends T[K]>(obj: T, key: K, value: V): void {
@BoBeenLee
BoBeenLee / fetchResource.js
Created March 9, 2018 05:39
High Order Component fetchResource
class fetchResource = get => WrappedComponent =>
class extends React.Component {
state = { resource: null };
componentDidMount() {
get(this.props)
.then(resource => this.setState({ resource }));
}
render() {