Skip to content

Commit

Permalink
Change arrow functions to function declarations (#8412)
Browse files Browse the repository at this point in the history
- The JavaScript template uses a function declaration to define the component, the TypeScript template and a page of the documentation used arrow functions. Changed it to use function declarations for consistency and readability.
  • Loading branch information
lewislbr authored Feb 3, 2020
1 parent 1cbc6f7 commit 687c4eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions docusaurus/docs/adding-images-fonts-and-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ One way to add SVG files was described in the section above. You can also import

```js
import { ReactComponent as Logo } from './logo.svg';
const App = () => (
<div>
{/* Logo is an actual React component */}
<Logo />
</div>
);

function App() {
return (
<div>
{/* Logo is an actual React component */}
<Logo />
</div>
);
}
```

This is handy if you don't want to load SVG as a separate file. Don't forget the curly braces in the import! The `ReactComponent` import name is significant and tells Create React App that you want a React component that renders an SVG, rather than its filename.
Expand Down
2 changes: 1 addition & 1 deletion packages/cra-template-typescript/template/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import logo from './logo.svg';
import './App.css';

const App = () => {
function App() {
return (
<div className="App">
<header className="App-header">
Expand Down

1 comment on commit 687c4eb

@entozoon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mightn't it be better to keep the arrow function here and replace the function declaration in the JS template?
I mean, it's personal preference to some extent but the consensus appears to be using arrows (when outside of a class), plus easier to change to export.
I'm happy to make the changes if sensible

Please sign in to comment.