简体   繁体   中英

React Typescript stateless component, SFC vs StatelessComponent

I can use either of the following to create react stateless component using typescript. But what is the difference between these two?

type SFC<P = {}> = FunctionComponent<P>;

type StatelessComponent<P = {}> = FunctionComponent<P>;

Digging into the types definitions file for React, we can see SFC is simply an equivalent type for a StatelessComponent.

Its personal preference which syntax you prefer.

@types/react/index.d.ts

type SFC<P = {}> = StatelessComponent<P>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM