This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Select = <IdType extends string>(props: { | |
options: Array<{ | |
id: IdType; | |
name: string; | |
}>; | |
selectedItemId?: IdType; | |
onSelect: (id: IdType) => void; | |
}) => ( | |
<select | |
value={props.selectedItemId ?? ''} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Select | |
onSelect={id => { | |
// Do something with id | |
}} | |
options={[ | |
{id: Size.Small, name: 'Small'}, | |
{id: Size.Medium, name: 'Medium'}, | |
{id: Size.Large, name: 'Large'}, | |
]} | |
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Select<Size> | |
onSelect={id => { | |
// Do something with id | |
}} | |
> | |
<option value={Size.Small}>Small</option> | |
<option value={Size.Medium}>Medium</option> | |
<option value={Size.Large}>Large</option> | |
</Select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Select | |
onSelect={id => { | |
// Do something with id | |
}} | |
> | |
<option value={Size.Small}>Small</option> | |
<option value={Size.Medium}>Medium</option> | |
<option value={Size.Large}>Large</option> | |
</Select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const List = <ItemType extends {id: string}>(props: { | |
items: ItemType[]; | |
renderItem: (item: ItemType) => React.ReactNode; | |
}) => ( | |
<ul> | |
{props.items.map(item => ( | |
<li key={item.id}>{props.renderItem(item)}</li> | |
))} | |
</ul> | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const List = <ItemType extends any>(props: { | |
items: ItemType[]; | |
renderItem: (item: ItemType) => React.ReactNode}; | |
) => ( | |
<ul> | |
{props.items.map(item => ( | |
<li key={item.id}>{props.renderItem(item)}</li> | |
))} | |
</ul> | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const List = <ItemType extends any>(props: { | |
items: ItemType[]; | |
renderItem: (item: ItemType) => React.ReactNode; | |
}) => ( | |
<>{props.items.map(props.renderItem)}</> | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const List = (props: { | |
items: any[]; | |
renderItem: (item: any) => React.ReactNode; | |
}) => ( | |
<>{props.items.map(props.renderItem)}</> | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<List | |
items={notProducts} | |
renderItem={notAProduct => ( | |
<p> | |
{notAProduct.name}: {notAProduct.code} | |
</p> | |
)} | |
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<List | |
items={products} | |
renderItem={product => ( | |
<p> | |
{product.name}: ${product.proice} | |
</p> | |
)} | |
/> |