Stateless React Components in Typescript

suggest change

React components that are pure functions of their props and do not require any internal state can be written as JavaScript functions instead of using the standard class syntax, as:

import React from 'react'

const HelloWorld = (props) => (<h1>Hello, {props.name}!</h1>);

The same can be achieved in TypeScript using the React.SFC type (later renamed React.FC):

import * as React from 'react';

interface GreeterProps {
   name: string
}

const Greeter: React.SFC<GreeterProps> = props =>
    <h1>Hello, {props.name}!</h1>;

Note that the name React.SFC is an alias for React.StatelessComponent, so either can be used.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents