Skip to content

Instantly share code, notes, and snippets.

View kwoncharles's full-sized avatar
🐎

Charles Kwoncheol Shin kwoncharles

🐎
View GitHub Profile
@kwoncharles
kwoncharles / WithLogging.ts
Created June 30, 2021 08:19
with logging example
let amplitude: any;
let ga: any;
function WithLogging({
action,
eventName,
children,
}: {
action: 'view' | 'click' | 'focus';
eventName: string;
@kwoncharles
kwoncharles / Page.jsx
Created December 24, 2020 00:35
You might need render props
function Page() {
return (
<Layout>
{/* Tab의 상태는 WithTab 내부로 추상화 */}
<WithTab items={tabItems}>
{selectedTab => {
switch (selectedTab) {
case 'LOGIN':
return <Login />
case 'JOIN':
@kwoncharles
kwoncharles / 1.Tabs.jsx
Last active December 26, 2020 08:23
Render Props Tab
// Tabs.jsx
import React from 'react'
function Tabs({ children }) {
const [selectedTab, setTab] = React.useState(initialTab)
return (
<ul className="tab-container">
{children(selectedTab, setTab)}
</ul>
@kwoncharles
kwoncharles / example.jsx
Created December 24, 2020 00:29
Render Props short example
// 일반 컴포넌트
<Button>
눌러주세요
</Button>
// Render Props 컴포넌트
<Button>
{() => <>눌러주세요</>}
</Button>
@kwoncharles
kwoncharles / 1.Tabs.jsx
Last active December 26, 2020 08:23
compound components Tab
// Tabs.jsx
import React from 'react'
const TabContext = React.createContext()
function Tabs({ children }) {
const [selectedTab, setTab] = React.useState(initialTab)
return (
<TabContext.Provider value={{ selectedTab, setTab }}>
@kwoncharles
kwoncharles / index.html
Created December 24, 2020 00:24
select tag example
<select>
<option>당근</option>
<option>양파</option>
<option>마늘</option>
<option>배추</option>
<option>오이</option>
</select>
@kwoncharles
kwoncharles / Tab.jsx
Last active December 26, 2020 08:22
composition tab3
// Tabs.js
import React from 'react'
function Tabs({ children }) {
const [selectedTab, setTab] = React.useState(initialTab)
return (
<ul className="tab-container">
{React.Children.map(children, child => (
React.cloneElement(child, {
@kwoncharles
kwoncharles / example.jsx
Created December 24, 2020 00:21
composition tab 2
function Page() {
return (
<Tabs>
{tabItems.map(tabItem => (
<Tabs.Item value={tabItem}>
{tabItem}
</Tabs.Item>
))}
</Tabs>
)
@kwoncharles
kwoncharles / example.jsx
Last active December 26, 2020 08:23
composition tab1
function Page() {
const [selectedTab, setTab] = React.useState(initialTab)
return (
<Tabs>
{tabItems.map(tabItem => (
<Tabs.Item
value={tabItem}
isSelected={selectedTab === tabItem}
onSelect={setTab}
@kwoncharles
kwoncharles / example.jsx
Last active December 26, 2020 08:24
Giant Tab Usage
function Page() {
const [tab, setTab] = React.useState(initialTab)
return (
<Tabs
items={tabItems}
onSelectTab={setTab}
selectedTab={tab}
/>
)