Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Refreshes documentation #35

Merged
merged 7 commits into from
Apr 28, 2018
Merged

Conversation

ashfurrow
Copy link
Contributor

@ashfurrow ashfurrow commented Mar 28, 2018

Hello! This PR updates the documentation in this repo to reflect more contemporary practices. The PR does the following:

  • Updates the readme docs.
  • Deletes all existing code and re-generates it based on the new readme (and in the ExampleProject directory).

Thanks to @orta for his help working through this.

Fixes #34.

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.
@msftclas
Copy link

msftclas commented Mar 28, 2018

CLA assistant check
All CLA requirements met.

@orta
Copy link
Contributor

orta commented Apr 4, 2018

We've moved these changes to also be on the React Native blog ^

@phwb
Copy link

phwb commented Apr 5, 2018

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.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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).
Copy link
Member

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:
Copy link
Member

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.
Copy link
Member

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.

Copy link
Contributor Author

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 👍

Copy link
Contributor Author

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
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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 = {
Copy link
Member

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).
Copy link
Member

Choose a reason for hiding this comment

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

ran -> run

Copy link
Member

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.
Copy link
Member

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

@ashfurrow
Copy link
Contributor Author

You got it, I'll get those changes in today. Thanks!

@@ -0,0 +1,83 @@
import * as React from "react"

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.

@orta
Copy link
Contributor

orta commented Apr 7, 2018

These changes will need to be migrated over to the RN blog post too 👍

@ashfurrow
Copy link
Contributor Author

Good idea @orta, I've done that here: facebook/react-native-website@fad2e85

@orta
Copy link
Contributor

orta commented Apr 19, 2018

Poke

@bryantee
Copy link

Are we just waiting for @DanielRosenwasser to approve changes?

@DanielRosenwasser DanielRosenwasser merged commit 3fc367a into microsoft:master Apr 28, 2018
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 28, 2018

Thank you so much for all the work here!! 😄 ⭐️ 👏

@ashfurrow
Copy link
Contributor Author

🎉🙇🤗

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants