Define non-arrow React functional component for TypeScript?

前端 未结 3 1412
面向向阳花
面向向阳花 2021-01-17 23:32

You can define a React functional component\'s types in TypeScript with this:

export const Component: React.FC = () => {
  return // Stuff
};
         


        
3条回答
  •  无人共我
    2021-01-17 23:57

    If you want to use the full type of a function to type a non-arrow function, you can use something like this (typescript documentation) :

    let myAdd: (x: number, y: number) => number =
        function(x: number, y: number): number { return x + y; };
    

    In your case:

    const MyComponent: React.FC = function() {
      return 
    ; };

提交回复
热议问题