-
Notifications
You must be signed in to change notification settings - Fork 210
Conversation
Cleans out old files. First draft of setup instructions. Removes old files. Updates instructions. Wraps up docs refresh. Adds example project. Runs Readme and code through Prettier. Removes yarn start specifier. Updates Hello component for modern conventions. Adds git commit instructions. Increases enthusiasm in test.
We've moved these changes to also be on the React Native blog ^ |
Hi, you are going to merge this PR? I want to translate this guide in to russian languge, but i want to do this with newest inforamtion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't gotten the chance to try this out, but the changes look great.
Apart from the requested changes, one thing I'd appreciate is if you could break each sentence onto its own line. It makes diffs significantly easier to review.
README.md
Outdated
|
||
## Migrating to TypeScript | ||
|
||
Rename the generated `App.js` and `__tests_/App.js` files to `App.tsx`. `index.js` needs to use the `.js` extension. All new files should use the `.tsx` extension (or `.ts` if the file doesn't contain any JSX). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__tests_
-> __tests__
README.md
Outdated
|
||
Rename the generated `App.js` and `__tests_/App.js` files to `App.tsx`. `index.js` needs to use the `.js` extension. All new files should use the `.tsx` extension (or `.ts` if the file doesn't contain any JSX). | ||
|
||
If you tried to run the app now, you'd get an error like `object prototype may only be an object or null`. This is caused by a failure to import the default export from React as well as a named export on the same line. Open `App.tsx` and modify the import at the top of the file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried -> try, you'd -> you'll
README.md
Outdated
+import { Component } from 'react'; | ||
``` | ||
|
||
Some of this has to do with differences in how Babel and TypeScript interoperate with CommonJS modules. In the future, the two will stabilize on the same behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure you shouldn't need to use this if you use esModuleInterop
, which I think is appropriate for React Native users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll look into this to verify 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at couldn't get this to work. I did find an open issue for this, so it should be possible to remove this once TypeScript has been patched to resolve that issue.
README.md
Outdated
|
||
This will configure Jest to run `.ts` and `.tsx` files with `ts-jest`. | ||
|
||
## Installing Dependency Type Declarations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installing type declaration dependencies
README.md
Outdated
|
||
## Installing Dependency Type Declarations | ||
|
||
To get the best experience in TypeScript, we want the type-checker to understand the shape and API of our dependencies. Some libraries will publish their packages with `.d.ts` files (type declaration/type definition files), which can describe the shape of the underlying JavaScript. For other libraries, we'll need to explicitly install the appropriate package in the `@types/` npm scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the comma before "which can describe"
README.md
Outdated
|
||
## Adding a Component | ||
|
||
We can now add a component to our app. Let's go ahead and create a `Hello.tsx` component. Create a `components` directory and add the following example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a components
directory in src
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The react-native init MyAwesomeProject
doesn't generate a src
directory, it just puts components
in the root of the project, alongside package.json
. If this is something we want to change, let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my mistake, I thought that the new components were still in src/components
. Gotcha.
README.md
Outdated
We can now add a component to our app. Let's go ahead and create a `Hello.tsx` component. Create a `components` directory and add the following example. | ||
|
||
```ts | ||
// components/Hello.tsx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/Hello.tsx
throw new Error("You could be a little more enthusiastic. :D") | ||
} | ||
|
||
this.state = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if we're going to use state
, we should reduce the complexity and just forget about onIncrement
and onDecrement
as props, and update state directly. So I'd define
onIncrement = () => this.setState({ enthusiasmLevel: this.state.enthusiasmLevel + 1 });
onDecrement = () => this.setState({ enthusiasmLevel: this.state.enthusiasmLevel - 1 });
README.md
Outdated
}) | ||
``` | ||
|
||
The first time the test is ran, it will create a snapshot of the DOM and store it in the `components/__tests__/__snapshots__/Hello.tsx.snap` file. When you modify your component, you'll need to update the snapshots and review the update for inadvertent changes. You can read more about testing React Native components [here](https://facebook.github.io/jest/docs/en/tutorial-react-native.html). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ran -> run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm not sure if it's appropriate to call it a snapshot of the DOM. Maybe a snapshot of the rendered component.
README.md
Outdated
|
||
## Next Steps | ||
|
||
Check out [our React tutorial](https://github.com/DanielRosenwasser/React-TypeScript-Tutorial) where we also cover topics like state management with [Redux](http://redux.js.org). These same subjects can be applied when writing React Native apps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed to https://github.com/Microsoft/TypeScript-React-Starter
You got it, I'll get those changes in today. Thanks! |
ExampleProject/components/Hello.tsx
Outdated
@@ -0,0 +1,83 @@ | |||
import * as React from "react" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could me
import React from "react"
now that we have allowSyntheticDefaultImports esModuleInterop enabled.
These changes will need to be migrated over to the RN blog post too 👍 |
Good idea @orta, I've done that here: facebook/react-native-website@fad2e85 |
Poke |
Are we just waiting for @DanielRosenwasser to approve changes? |
Thank you so much for all the work here!! 😄 ⭐️ 👏 |
🎉🙇🤗 |
Hello! This PR updates the documentation in this repo to reflect more contemporary practices. The PR does the following:
Hello
component to be a bit more modern.ExampleProject
directory).Thanks to @orta for his help working through this.
Fixes #34.