December 2019
Intermediate to advanced
598 pages
12h 21m
English
Let's perform the following steps to create a generic Field component:
import { FC } from 'react';/** @jsx jsx */import { css, jsx } from '@emotion/core';import { fontFamily, fontSize, gray5, gray2, gray6,} from './Styles';
interface Props { name: string; label?: string; type?: 'Text' | 'TextArea' | 'Password';}
So, we have props for the name field, its label, and its type.
Notice the TypeScript type for the type prop. This is a union type of string literals and means that the type prop can only be Text, TextArea, or Password.
Read now
Unlock full access