Last active
March 17, 2022 22:29
-
-
Save dejanvasic85/ad6f065844093fc9d8a99f7ce708961e to your computer and use it in GitHub Desktop.
Typescript string array to Type
This file contains 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
export const layout = ['inline', 'stacked'] as const; | |
export type Layout = typeof layout[number]; | |
// Then it can be used in React props | |
interface Props { | |
layout: Layout; | |
} | |
const Component = ({ layout }: Props) => ( | |
<div style={{ display: 'flex', flexDirection: layout === 'inline' ? 'column' : 'row' }}></div> | |
) | |
// Storybook uses the layout array | |
export default { | |
title: 'Component', | |
argTypes: { layout: { options: layout } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Allowing public view.
This is how to convert an array of strings to a Typescript type.