O
O
Ostic2019-05-31 16:39:12
typescript
Ostic, 2019-05-31 16:39:12

What are the best component types to use in react + ts?

Hello.
It is possible like this:

FC
const Component1: React.FC = () => {
  return (
    <div>
       FC
    </div>
  )
}

And you can do it like this:
JSX.Element
function Component2(){
  return (
    <div>
      JSX.Element
    </div>
  )
}

Is there any difference, restrictions, "pitfalls"?
I didn’t see any difference in the console - one to one, only in one case I explicitly declare the type, and in the second ts itself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-31
@Ostic

interface Props {
  someProp: string;
}

const Example: React.FC<Props> = ({ someProp }) => (
  <div>{someProp}</div>
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question