Skip to content

Commit

Permalink
[Docs] Merge with-mobx-state-tree with with-mobx-state-tree-typescrip…
Browse files Browse the repository at this point in the history
…t example (#40306)

## Changes

see commits

## Context

As discussed in #40302 (comment) we are going to merge the mobx examples.

#40302

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
  • Loading branch information
HaNdTriX committed Sep 8, 2022
1 parent b85fcea commit 2b9268a
Show file tree
Hide file tree
Showing 25 changed files with 17 additions and 289 deletions.
4 changes: 0 additions & 4 deletions examples/with-mobx-state-tree-typescript/.babelrc

This file was deleted.

36 changes: 0 additions & 36 deletions examples/with-mobx-state-tree-typescript/.gitignore

This file was deleted.

34 changes: 1 addition & 33 deletions examples/with-mobx-state-tree-typescript/README.md
@@ -1,35 +1,3 @@
# MobX State Tree with TypeScript example

Usually splitting your app state into `pages` feels natural but sometimes you'll want to have global state for your app. This is an example on how you can use mobx that also works with our universal rendering approach.

In this example we are going to display a digital clock that updates every second. The first render is happening in the server and the date will be `00:00:00`, then the browser will take over and it will start updating the date.

To illustrate SSG and SSR, go to `/ssg` and `/ssr`, those pages are using Next.js data fetching methods to get the date in the server and return it as props to the page, and then the browser will hydrate the store and continue updating the date.

The trick here for supporting universal mobx is to separate the cases for the client and the server. When we are on the server we want to create a new store every time, otherwise different users data will be mixed up. If we are in the client we want to use always the same store. That's what we accomplish on `store.js`

The clock, under `components/Clock.js`, has access to the state using the `inject` and `observer` functions from `mobx-react`. In this case Clock is a direct child from the page but it could be deep down the render tree.

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-mobx-state-tree-typescript)

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-mobx-state-tree-typescript&project-name=with-mobx-state-tree-typescript&repository-name=with-mobx-state-tree-typescript)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
```

```bash
yarn create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
```

```bash
pnpm create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
**Note:** This example has been moved to [examples/with-mobx-state-tree](../with-mobx-state-tree/)
5 changes: 0 additions & 5 deletions examples/with-mobx-state-tree-typescript/next-env.d.ts

This file was deleted.

24 changes: 0 additions & 24 deletions examples/with-mobx-state-tree-typescript/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions examples/with-mobx-state-tree/.babelrc

This file was deleted.

12 changes: 6 additions & 6 deletions examples/with-mobx-state-tree/README.md
@@ -1,4 +1,4 @@
# MobX State Tree example
# MobX State Tree with TypeScript example

Usually splitting your app state into `pages` feels natural but sometimes you'll want to have global state for your app. This is an example on how you can use mobx that also works with our universal rendering approach.

Expand All @@ -12,24 +12,24 @@ The clock, under `components/Clock.js`, has access to the state using the `injec

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-mobx-state-tree)
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) or preview live with [StackBlitz](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/with-mobx-state-tree-typescript)

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-mobx-state-tree&project-name=with-mobx-state-tree&repository-name=with-mobx-state-tree)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-mobx-state-tree-typescript&project-name=with-mobx-state-tree-typescript&repository-name=with-mobx-state-tree-typescript)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example with-mobx-state-tree with-mobx-state-tree-app
npx create-next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
```

```bash
yarn create next-app --example with-mobx-state-tree with-mobx-state-tree-app
yarn create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
```

```bash
pnpm create next-app --example with-mobx-state-tree with-mobx-state-tree-app
pnpm create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
25 changes: 0 additions & 25 deletions examples/with-mobx-state-tree/components/Clock.js

This file was deleted.

35 changes: 0 additions & 35 deletions examples/with-mobx-state-tree/components/SampleComponent.js

This file was deleted.

16 changes: 9 additions & 7 deletions examples/with-mobx-state-tree/package.json
Expand Up @@ -6,15 +6,17 @@
"start": "next start"
},
"dependencies": {
"mobx": "3.3.1",
"mobx-react": "^4.0.4",
"mobx-state-tree": "1.0.1",
"mobx": "^6.6.1",
"mobx-react": "^7.5.2",
"mobx-react-lite": "^3.4.0",
"mobx-state-tree": "^5.1.6",
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/core": "7.14.5",
"@babel/plugin-proposal-decorators": "^7.1.2"
"@types/node": "^18.7.15",
"@types/react": "^18.0.18",
"typescript": "^4.8.2"
}
}
12 changes: 0 additions & 12 deletions examples/with-mobx-state-tree/pages/_app.js

This file was deleted.

5 changes: 0 additions & 5 deletions examples/with-mobx-state-tree/pages/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions examples/with-mobx-state-tree/pages/other.js

This file was deleted.

17 changes: 0 additions & 17 deletions examples/with-mobx-state-tree/pages/ssg.js

This file was deleted.

File renamed without changes.
18 changes: 0 additions & 18 deletions examples/with-mobx-state-tree/pages/ssr.js

This file was deleted.

File renamed without changes.
52 changes: 0 additions & 52 deletions examples/with-mobx-state-tree/store.js

This file was deleted.

File renamed without changes.
Expand Up @@ -13,7 +13,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"experimentalDecorators": true
"incremental": true
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
Expand Down

0 comments on commit 2b9268a

Please sign in to comment.