Commit Graph

2457 Commits

Author SHA1 Message Date
Ian Schmitz
b855da5732 Remove outdated babel plugins (#8353)
Updates dependencies and removes babel plugins that are now covered by `@babel/preset-env`.

Co-authored-by: hdineen <hdineen@hubspot.com>
2020-01-30 14:18:09 -08:00
Vincent Semrau
4bf14fa665 Downgrade open from 7.0.0 to 6.4.0 (#8364) 2020-01-23 13:37:27 +01:00
Retsam
dada03574a Remove React.FC from Typescript template (#8177)
This removes `React.FC` from the base template for a Typescript project.

Long explanation for a small change: 

`React.FC` is unnecessary: it provides next to no benefits and has a few downsides.  (See below.)  I see a lot of beginners to TS+React using it, however, and I think that it's usage in this template is a contributing factor to that, as the prominence of this template makes it a de facto source of "best practice".  

### Downsides to React.FC/React.FunctionComponent

##### Provides an implicit definition of `children`

Defining a component with `React.FC` causes it to implicitly take `children` (of type `ReactNode`).  It means that all components accept children, even if they're not supposed to, allowing code like:

```ts
const App: React.FC = () => { /*... */ };
const Example = () => {
	<App><div>Unwanted children</div></App>
}
```

This isn't a run-time error, but it is a mistake and one that would be caught by Typescript if not for `React.FC`. 

##### Doesn't support generics.
I can define a generic component like:
```ts
type GenericComponentProps<T> = {
   prop: T
   callback: (t: T) => void
}
const GenericComponent = <T>(props: GenericComponentProps<T>) => {/*...*/}
```

But it's not possible when using `React.FC` - there's no way to preserve the unresolved generic `T` in the type returned by `React.FC`.

```ts
const GenericComponent: React.FC</* ??? */> = <T>(props: GenericComponentProps<T>) => {/*...*/}
```

##### Makes "component as namespace pattern" more awkward.
It's a somewhat popular pattern to use a component as a namespace for related components (usually children):

```jsx
<Select>
	<Select.Item />
</Select>
```

This is possible, but awkward, with `React.FC`:

```tsx
const  Select: React.FC<SelectProps> & { Item: React.FC<ItemProps> } = (props) => {/* ... */ }
Select.Item = (props) => { /*...*/ }
```

but "just works" without `React.FC`:

```tsx
const Select = (props: SelectProps) => {/* ... */}
Select.Item = (props) => { /*...*/ }
```

##### Doesn't work correctly with defaultProps

This is a fairly moot point as in both cases it's probably better to use ES6 default arguments, but...

```tsx
type  ComponentProps = { name: string; }

const  Component = ({ name }: ComponentProps) => (<div>
	{name.toUpperCase()} /* Safe since name is required */
</div>);
Component.defaultProps = { name: "John" };

const  Example = () => (<Component />) /* Safe to omit since name has a default value */
```
This compiles correctly.  Any approach with `React.FC` will be slightly wrong: either `React.FC<{name: string}>` will make the prop required by consumers, when it should be optional, or `React.FC<{name?: string}>` will cause `name.toUpperCase()` to be a type error.  There's no way to replicate the "internally required, externally optional" behavior which is desired.

##### It's as long, or longer than the alternative: (especially longer if you use `FunctionalComponent`):
Not a huge point, but it isn't even shorter to use `React.FC` 
```ts
const C1: React.FC<CProps> = (props) => { }
const C2 = (props: CProps) => {};
```

### Benefits of React.FC

##### Provides an explicit return type

The only benefit I really see to `React.FC` (unless you think that implicit `children` is a good thing) is that it specifies the return type, which catches mistakes like:

```ts
const Component = () => {
   return undefined; // components aren't allowed to return undefined, just `null`
}
```

In practice, I think this is fine, as it'll be caught as soon as you try to use it:

```ts
const Example = () => <Component />; // Error here, due to Component returning the wrong thing
```

But even with explicit type annotations, `React.FC` still isn't saving very much boilerplate:

```ts
const Component1 = (props: ComponentProps): ReactNode => { /*...*/ }
const Component2: FC<ComponentProps> = (props) => { /*...*/ }
```
2020-01-22 13:32:49 -08:00
Reece Dunham
a608c5affc Update Dependencies (#8324) 2020-01-21 14:46:01 -08:00
Evan Grim
f875bb0c84 Minor grammatical edit (#8293) 2020-01-16 11:25:28 -08:00
Tom Valorsa
94932bedc0 Allow additional package keys and add blacklist (#8082) (#8219) 2020-01-12 14:10:03 +02:00
Kai Hao
fa85f030de Support shorthand scoped templates (#8298) 2020-01-12 14:07:07 +02:00
Alex Guerra
c03bb366e0 Replace favicon in templates (#8194)
The old favicon was the same as the official react documentation, which is a minor annoyance during development when trying to find the tab you want. The new favicon is just the old with inverted colors.

Closes #7957
2019-12-30 13:53:00 -06:00
Sony AK
3f2037bb2a Little typo (#8212) 2019-12-20 13:55:58 +01:00
Andreas Cederström
88a543549b Bump babel-plugin-tester and fix breaking changes (#8171) 2019-12-19 10:52:19 +01:00
Brian Muenzenmeyer
18e56da3b7 fix: proactively append to .gitignore during init (#8028) 2019-12-18 20:42:55 +02:00
Alex Guerra
30eaab4ef2 Minor refactors in create-react-app (#8178)
- Remove templates version minimum stopgap.
- Replace indexOf with more idiomatic alternatives.
- Inline errorLogFilePatterns.
- Alphabetize validFiles.
- Simplify log file removal code.
- Move unconditional console.log() call outside of isSafe.
- Differentiate conflicting directories from files.
- Document yarn version special case.
- Inline printValidationResults.
- Standardize checkAppName output on failure.
- Add link for checkThatNpmCanReadCwd.

Functionally the code should be exactly the same.
2019-12-16 14:56:37 -06:00
Peet Goddard
1a13b594ae Update PWA docs links to point to template package (#8147) 2019-12-15 16:21:05 -05:00
Jerome De Leon
f31485567b Add package-runner note to readme (#8132)
* Add package-runner note to readme

* Add link to `yarn create`
2019-12-15 16:19:41 -05:00
Andreas Cederström
f26de73e64 Bump internal dependencies (#8176)
* Bump dependencies in react-dev-utils

* Bump dependencies in react-app-polyfill

* Bump dependencies in create-react-app

* Bump dependencies in react-error-overlay

* Bump dependencies in react-scripts

* Bump react
2019-12-14 06:33:53 +01:00
Ian Sutherland
ab2976f350 Add link to Netlify in README 2019-12-13 14:23:13 -05:00
Andreas Cederström
349a92a8c8 Bump chalk (#8164) 2019-12-13 20:02:04 +01:00
Andreas Cederström
9922275c14 Bump pkgUp (#8163) 2019-12-13 10:57:54 +01:00
Alex Guerra
ebcffdacdc Add current version and bin location to --info output (#8168)
Make the --info subcommand outuput the current version information and the location of the file being run. Our issue template tells users to provide the output of --info, so having the current version is incredibly helpful, especially since it doesn't necessarily match the globally installed version that envinfo outputs. Knowing the location helps us determine whether the running bin is globally installed or in the local node_modules.
2019-12-13 10:56:48 +01:00
Reece Dunham
8d1a4f2fce [Security] Update terser webpack plugin (#8102)
* security: update terser webpack plugin
2019-12-11 17:39:30 +01:00
Endi
1f1594d520 chore: update docusaurus & tweak site (#8111) 2019-12-10 15:42:30 -05:00
Vadzim
b8ff97be72 Fix typo in comment: ?. is right, not .? (#8124)
This is just a comment fix.

Actual optional chaining operator syntax is `?.`, not `.?`.
2019-12-09 14:09:06 -08:00
Wojciech Zieliński
53a48c40b3 Add slashes to WebSocket protocol URL (#8116) 2019-12-08 22:57:34 -08:00
Simon Donaldson
0327d8952a Fix CSS font-face minification (#8106) 2019-12-08 22:21:47 -08:00
Ian Schmitz
0b293e9432 Fix CI build (#8122) 2019-12-08 21:05:52 -08:00
Sean Zhu
b19bffe110 Remove error for @typescript-eslint/no-namespace (#7803)
Declare namespaces are supported by babel now, and babel will throw with a nice error message for non-declare namespaces, so this rule is unnecessary. Closes #7651.
2019-12-06 14:44:22 -06:00
Trontor
8330e7c0de Fix typo in CHANGELOG.md (#8080) 2019-12-05 20:44:08 -08:00
Ian Schmitz
2ace7c2c4e Add custom-templates to docs sidebar (#8077) 2019-12-04 22:38:23 -08:00
Mike Caulley
9f4cb4f0c0 webpackHotDev now uses wss when https is used (#8079) 2019-12-04 22:35:07 -08:00
Ian Sutherland
9a817dd0d7 Publish
- babel-plugin-named-asset-import@0.3.5
 - babel-preset-react-app@9.1.0
 - cra-template-typescript@1.0.0
 - cra-template@1.0.0
 - create-react-app@3.3.0
 - eslint-config-react-app@5.1.0
 - react-app-polyfill@1.0.5
 - react-dev-utils@10.0.0
 - react-error-overlay@6.0.4
 - react-scripts@3.3.0
create-react-app@3.3.0 babel-plugin-named-asset-import@0.3.5 cra-template@1.0.0 babel-preset-react-app@9.1.0 eslint-config-react-app@5.1.0 react-app-polyfill@1.0.5 react-dev-utils@10.0.0 react-error-overlay@6.0.4 react-scripts@3.3.0 cra-template-typescript@1.0.0 v3.3.0
2019-12-04 17:05:06 -07:00
Ian Sutherland
0b45600949 Update CHANGELOG 2019-12-04 14:00:29 -07:00
Ian Sutherland
9654befd03 Prepare 3.3.0 release 2019-12-04 13:55:34 -07:00
Brody McKee
29c5e55ade Update template docs (#8050)
* Update template docs

* Update custom-templates.md

* Update custom-templates.md


Co-authored-by: Ian Sutherland <ian@iansutherland.ca>
2019-11-29 10:40:25 -07:00
Ian Sutherland
f6ba862500 Add TypeScript peer dependency to react-scripts (#8038) 2019-11-28 15:32:19 -07:00
Ian Sutherland
fffc777a93 Remove no-unexpected-multiline rule (#8039) 2019-11-28 14:07:10 -07:00
Ian Sutherland
6a3ccc3e7d Update CODEOWNERS 2019-11-27 15:45:32 -07:00
Ian Sutherland
821fe6bb8d Update CHANGELOG 2019-11-27 15:40:32 -07:00
Ian Sutherland
99d71f3068 Re-enable GitHub Actions (#8029) 2019-11-25 15:15:38 -07:00
Ian Schmitz
1a66971f9e Bump dependencies (#8024) 2019-11-24 15:48:15 -08:00
Ian Schmitz
82009f570d Bump webpack-dev-server (#7988) 2019-11-24 14:18:33 -08:00
Ben Blank
5d24a5e88f Prefix apple-touch-icon links with PUBLIC_URL. (#8005) 2019-11-24 13:54:02 +02:00
Max Davidson
4604c5e52c Override no-unused-expressions with the typescript-eslint version (#8003)
Fixes issues with optional chaining
2019-11-19 19:15:25 -08:00
Brody McKee
23d5776724 Add scripts support to templates (#7989) 2019-11-19 12:14:31 +02:00
Ian Schmitz
df5088da4d Unpin dependencies in react-app-polyfill (#7999) 2019-11-18 19:17:06 -08:00
Ali Waseem
4b4f3f2cf7 added e2e test for checking typescript template with unsupported node (#7844) 2019-11-18 16:06:44 -07:00
Ian Schmitz
3aaa3fa895 Add contributors section to readme (#7995) 2019-11-18 13:17:05 -08:00
Klas Björkqvist
e7cdde6ab8 Support scoped templates (#7991) 2019-11-18 09:35:14 +02:00
Ian Schmitz
58b4738a49 Bump dependencies (#7986) 2019-11-15 20:15:52 -08:00
Ian Sutherland
3d6d0a1f9c Prepare 3.3.0 beta 2019-11-14 15:21:12 -07:00
Ian Sutherland
9df95df540 Temporarily disable GitHub Actions (#7978) 2019-11-13 17:07:10 -07:00