Commit Graph

1427 Commits

Author SHA1 Message Date
Ian Schmitz
720d90bc88 Sync dependencies babel config (#8120) 2020-01-30 14:41:39 -08:00
Rasmus Nørskov
ddcb7d50ac Add titleProp to SVGR ReactComponent type definition (#8099) 2020-01-30 14:33:44 -08:00
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
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
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
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
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
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
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
2019-12-04 17:05:06 -07:00
Ian Sutherland
9654befd03 Prepare 3.3.0 release 2019-12-04 13:55:34 -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 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
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
915108b650 Add placeholders where old template READMEs used to be (#7972) 2019-11-13 16:59:32 -07:00
Mateusz Burzyński
f01bfac190 Upgrade jest-watch-typeahead (#7956) 2019-11-09 17:57:16 -08:00
Ian Schmitz
5cdc3cc0b0 Add tests for optional chaining and null coalescing (#7952) 2019-11-08 23:03:23 -08:00
Renato Augusto Gama dos Santos
d12b4b6c53 Add optional chaining and nullish coalescing operators support (#7438) 2019-11-08 21:38:36 -08:00
Ian Schmitz
211694a8a2 Fix CI (#7951) 2019-11-08 18:54:16 -08:00
RJ Morgan
8a1ee2f7a5 Make JavaScript and TypeScript templates consistent (#7944) 2019-11-06 17:30:20 -07:00
Donavon West
10daea2efa No spinning React logo if prefers-reduced-motion (#7931) 2019-11-05 22:09:27 -07:00
Donavon West
d46da8989b fix seperators typo (#7932)
Its the little things that makes the big difference!  😁

Thanks
2019-11-05 21:26:46 +01:00
Ian Schmitz
9750738cce Add restoreMocks to supported jest config keys (#7921) 2019-11-02 23:07:44 -07:00
Dylan Staley
6d6dfa9ba5 Mark TypeScript as an optional peer dependency (#7860) 2019-10-30 21:05:29 -07:00
Andreas Cederström
b68c777792 Update open (#7910) 2019-10-30 20:58:29 -07:00
Tharun Rajendran
b4fe788fe7 Add numeric separator support (#7817) 2019-10-30 15:32:52 -07:00
Kent C. Dodds
2de57fe15a Add @testing-library to the default templates (#7881) 2019-10-29 14:36:55 -07:00