Skip to content

Instantly share code, notes, and snippets.

View kwoncharles's full-sized avatar
🐎

Charles Kwoncheol Shin kwoncharles

🐎
View GitHub Profile
@kwoncharles
kwoncharles / example.js
Created December 24, 2020 00:16
IoC Filter example
// 일반 filter
const dogs = filterDogs(animals)
// 제어역전 filter
const dogs = animals.filter(animal => animal.species === 'dog')
@kwoncharles
kwoncharles / example.jsx
Last active December 27, 2020 13:57
composition-compare
// 자이언트 컴포넌트
<Dialog
iconAboveTitle="fancy-icon"
title="안내"
description="이것은 멋진 내용을 담고 있는 안내입니다."
buttonPosition="bottom"
buttonAlign="vertical"
buttons={[{
label: '확인',
onClick: doSomething,
@kwoncharles
kwoncharles / example.jsx
Last active December 27, 2020 13:57
compose2
Dialog.Content = ({ title, description }) => (
<React.Fragment>
<Dialog.Title>
{title}
</Dialog.Title>
<Dialog.Description>
{description}
</Dialog.Description>
</React.Fragment>
)
@kwoncharles
kwoncharles / example.jsx
Last active December 27, 2020 13:58
compose1
function Page() {
return (
<Dialog>
<Dialog.Title>
안내
</Dialog.Title>
<Dialog.Description>
이것은 멋진 내용을 담고 있는 안내입니다.
</Dialog.Description>
<Dialog.ButtonContainer align="vertical">
@kwoncharles
kwoncharles / example.jsx
Last active December 27, 2020 13:58
apropcalypse
/* 컴포넌트 탄생! 깔끔하다 ✨ */
<Dialog
title="안내"
description="이것은 멋진 내용을 담고 있는 안내입니다."
button={{
label: '확인',
onClick: doSomething,
}}
/>
@kwoncharles
kwoncharles / App.jsx
Last active December 7, 2020 12:38
Body context example
import { BodyProvider } from './BodyContext'
function App() {
return (
<BodyProvider>
<Routes />
</BodyProvider>
)
}
@kwoncharles
kwoncharles / useDocumentOverflow.ts
Last active March 1, 2020 16:26
useDocumentOverflow example
// useDocumentOverflow.ts
import { useEffect } from 'react';
const defaultOverflow: string = 'auto';
function useDocumentOverflow(property: 'hidden' | 'scroll' | 'auto') {
useEffect(() => {
const bodyElement: HTMLBodyElement = document.getElementsByTagName('body')[0];
const previousOverflow: string = bodyElement.style.overflow || defaultOverflow;
bodyElement.style.overflow = property;
@kwoncharles
kwoncharles / SomeComponent.tsx
Created March 1, 2020 09:27
useInput hook example
function SomeComponent() {
const [value, onChangeInputValue, isValid] = useInput({
type: 'number',
maxValue: 10000,
autoFix: false,
});
const onSubmit = () => {
if (isValid) {
submitValue(value);
} else {
import { useState, useCallback } from 'react';
export interface DropdownBundle<T> {
isOpen: boolean;
selectedValue: T;
onClickDropdown: () => void;
onClickOption: (v: T) => void;
onRequestClose: () => void;
}
import { useState, useCallback } from 'react';
type returnType = [CheckItem[], (label: string) => void, () => void];
function useCheckList(checkList: CheckItem[]): returnType {
const [list, setList] = useState(checkList);
const onCheckItem = useCallback((label: string) => {
setList(prevList => prevList.map(item => {
if (label === item.label) {