在 React 中使用 TypeScript

typescript-reactopen in new window

行内样式 style

import CSS from 'csstype';

const h1Styles: CSS.Properties = {
  padding: '0.5rem',
  fontFamily: 'sans-serif',
  fontSize: '1.5rem',
};

export function Heading({ title } : { title: string} ) {
  return <h1 style={h1Styles}>{title}</h1>;
}

ReactNode ReactElement

JSX.Element ≈ ReactElement ⊂ ReactNode

import React, {ReactElement, ReactNode} from 'react';
上次更新:
Contributors: kyxiao