Stack

Stack

React

Function Components

We only use FC type when we need to pass and extract children from props 1. Otherwise, we use the function declaration. Refer here for a more extensive section explaining why React.FC should mostly be avoided.

// Avoid
interface Props {
  text?: string;
}
const Heading: React.FC<Props> = ({ text = 'Hello, world!' }) => {
  return <h1>{text}</h1>;
};
// Prefer
interface Props {
  text?: string;
}
function Heading({text = 'Hello, world!'}: Props) {
  return <h1>{text}</h1>;
}

Coding Patterns

let vs const

https://overreacted.io/on-let-vs-const/

Copy/paste is better than the wrong abstraction 2.

Footnotes

Footnotes

  1. Why “he” does not write React.FC on each function?

  2. Lee Robinson - Stack