Accepted answer

thanks all for the answers. they are correct but i was looking for a more detailed version. i did some more research and found this on react+typescript cheatsheets on github.

function components
these can be written as normal functions that take a props argument and return a jsx element.

type appprops = { message: string }; /* could also use interface */

const app = ({ message }: appprops) => <div>{message}</div>;

what about react.fc/react.functioncomponent? you can also write components with react.functioncomponent (or the shorthand react.fc):

const app: react.fc<{ message: string }> = ({ message }) => (

some differences from the "normal function" version:

it provides typechecking and autocomplete for static properties like displayname, proptypes, and defaultprops - however, there are currently known issues using defaultprops with react.functioncomponent. see this issue for details - scroll down to our defaultprops section for typing recommendations there.

it provides an implicit definition of children (see below) - however there are some issues with the implicit children type (e.g. definitelytyped#33006), and it might be considered a better style to be explicit about components that consume children, anyway.

const title: react.functioncomponent<{ title: string }> = ({
}) => <div title={title}>{children}</div>;

in the future, it may automatically mark props as readonly, though that's a moot point if the props object is destructured in the parameter list.

react.functioncomponent is explicit about the return type, while the normal function version is implicit (or else needs additional annotation).

in most cases, it makes very little difference which syntax is used, but the react.fc syntax is slightly more verbose without providing clear advantage, so precedence was given to the "normal function" syntax.


since you are using react and typescript, you should always use the first pattern, as it will ensure that your component is more strictly typed since it implies that the printname will be of type react functional component, and it takes in props of type props.

const printname: react.fc<props>

you may read the full interface definition for functional components on the react typescript typings repository.

the second example you have provided does not provide any form of typings, except that it is a function that takes a set of parameters of type props, and that it can return anything in general.

therefore, writing

const printname2 = (props:props)

is akin to

const printname2: jsx.element = (props:props) 

as typescript is definitely unable to automatically infer that it is a functional component.


best solution:

the second approach + a return type

const printname2 = ({ prop1, prop2 }: props): jsx.element => { /** */}

this gives you complete control over the props and is more explicit (there is no hidden magic).

link to github pr to remove react.fc

kent c dodds has some thoughts why this is here

sub-optimal solution:

the first version (react.fc) will add a few types for you - they come from the react typings

interface functioncomponent<p = {}> {
  (props: propswithchildren<p>, context?: any): reactelement | null;
  proptypes?: weakvalidationmap<p>;
  contexttypes?: validationmap<any>;
  defaultprops?: partial<p>;
  displayname?: string;

this approach is useful for a few reasons but an obvious one is if your component has children, then you don't need to manually add a children prop. it's not great because there are issues with default props and many components don't have children.


react.fc is not the preferable way to type a react component, here's a link.

i personally use this type:

const component1 = ({ prop1, prop2 }): jsx.element => { /*...*/ }

short list of react.fc cons:

  1. provides an implicit definition of children, even if your component doesn't need to have children. that might cause an error.
  2. doesn't support generics.
  3. doesn't work correctly with defaultprops.

Related Query

More Query from same tag