Skip to content

chore: remove React.FC #445

Open
Open
@davidsonsns

Description

@davidsonsns

What

  • Remove React.FC;

Why

  • Following React.FC pattern we add an extra label to all components. Components that aren't using children, will be able to get valid children prop without any reason;
  • vscode Intellisense will be very painful; Trying to be redirected to components definitions(F12) shows us at least two options. Without it, you'll be redirected instantly;
    Screen Shot 2021-01-12 at 21 16 20
  • Redundancies. As shown below, the component uses React.FC<JournalyEditorProps> and JournalyEditorProps;
const JournalyEditor: React.FC<JournalyEditorProps> = ({
  value,
  setValue,
  slateRef,
}: JournalyEditorProps) => {

Some references:
https://fettblog.eu/typescript-react-why-i-dont-use-react-fc/
facebook/create-react-app#8177

How

  • Create the generic type type WithChildren<T = {}> = T & { children?: React.ReactNode };. Which can be used on those components that in fact uses the prop children;
  • Remove React.FC from all components, refactoring it to set prop types after their definitions; e.g:
const JournalyEditor = ({
  value,
  setValue,
  slateRef,
}: JournalyEditorProps) => {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions