Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Basic] Function Component alternative #90

Closed
deadcoder0904 opened this issue Feb 21, 2019 · 2 comments
Closed

[Basic] Function Component alternative #90

deadcoder0904 opened this issue Feb 21, 2019 · 2 comments
Assignees
Labels
BASIC Basic Cheatsheet wontfix This will not be worked on

Comments

@deadcoder0904
Copy link

What cheatsheet is this about? (if applicable)

Basic cheatsheet

What's your issue or idea?

The function component can be reduced to

function App({ message: string }) {
  return <div>{message}</div>;
}

instead of

const App: React.FunctionComponent<{ message: string }> = function App({ message }) {
  return <div>{message}</div>;
}

which is quite big & is weird syntactically at least in vanilla JS

const App = function App({ message ) {
  return <div>{message}</div>;
}

Also, would love some examples in Function Components section of What's the difference? each bullet points :)

Examples would be much better on these 2 bullet points since it makes grasping easier -

  • If you need to use children property inside the function body, in the former case it has to be added explicitly. FunctionComponent already includes the correctly typed children property which then doesn't have to become part of your type.
  • Typing your function explicitly will also give you typechecking and autocomplete on its static properties, like displayName, propTypes, and defaultProps
@deadcoder0904 deadcoder0904 added the BASIC Basic Cheatsheet label Feb 21, 2019
@ferdaber
Copy link
Collaborator

You're welcome to make a PR with those changes! I think it's a good message to send as I personally never use the FunctionComponent annotation. It wasn't even until I became involved in this project that I realized people were using it.

@stale
Copy link

stale bot commented Aug 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

@stale stale bot added the wontfix This will not be worked on label Aug 20, 2020
@swyxio swyxio closed this as completed Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BASIC Basic Cheatsheet wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants