Skip to content

Commit 2b9268a

Browse files
authoredSep 8, 2022
[Docs] Merge with-mobx-state-tree with with-mobx-state-tree-typescript example (vercel#40306)
## Changes see commits ## Context As discussed in vercel#40302 (comment) we are going to merge the mobx examples. vercel#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)
1 parent b85fcea commit 2b9268a

25 files changed

+17
-289
lines changed
 

‎examples/with-mobx-state-tree-typescript/.babelrc

-4
This file was deleted.

‎examples/with-mobx-state-tree-typescript/.gitignore

-36
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
11
# MobX State Tree with TypeScript example
22

3-
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.
4-
5-
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.
6-
7-
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.
8-
9-
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`
10-
11-
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.
12-
13-
## Deploy your own
14-
15-
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)
16-
17-
[![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)
18-
19-
## How to use
20-
21-
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:
22-
23-
```bash
24-
npx create-next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
25-
```
26-
27-
```bash
28-
yarn create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
29-
```
30-
31-
```bash
32-
pnpm create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
33-
```
34-
35-
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)).
3+
**Note:** This example has been moved to [examples/with-mobx-state-tree](../with-mobx-state-tree/)

‎examples/with-mobx-state-tree-typescript/next-env.d.ts

-5
This file was deleted.

‎examples/with-mobx-state-tree-typescript/package.json

-24
This file was deleted.

‎examples/with-mobx-state-tree/.babelrc

-4
This file was deleted.
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MobX State Tree example
1+
# MobX State Tree with TypeScript example
22

33
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.
44

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

1313
## Deploy your own
1414

15-
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)
15+
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)
1616

17-
[![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)
17+
[![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)
1818

1919
## How to use
2020

2121
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:
2222

2323
```bash
24-
npx create-next-app --example with-mobx-state-tree with-mobx-state-tree-app
24+
npx create-next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
2525
```
2626

2727
```bash
28-
yarn create next-app --example with-mobx-state-tree with-mobx-state-tree-app
28+
yarn create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
2929
```
3030

3131
```bash
32-
pnpm create next-app --example with-mobx-state-tree with-mobx-state-tree-app
32+
pnpm create next-app --example with-mobx-state-tree-typescript with-mobx-state-tree-typescript-app
3333
```
3434

3535
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)).

‎examples/with-mobx-state-tree/components/Clock.js

-25
This file was deleted.

‎examples/with-mobx-state-tree/components/SampleComponent.js

-35
This file was deleted.

‎examples/with-mobx-state-tree/package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
"start": "next start"
77
},
88
"dependencies": {
9-
"mobx": "3.3.1",
10-
"mobx-react": "^4.0.4",
11-
"mobx-state-tree": "1.0.1",
9+
"mobx": "^6.6.1",
10+
"mobx-react": "^7.5.2",
11+
"mobx-react-lite": "^3.4.0",
12+
"mobx-state-tree": "^5.1.6",
1213
"next": "latest",
13-
"react": "^17.0.2",
14-
"react-dom": "^17.0.2"
14+
"react": "^18.2.0",
15+
"react-dom": "^18.2.0"
1516
},
1617
"devDependencies": {
17-
"@babel/core": "7.14.5",
18-
"@babel/plugin-proposal-decorators": "^7.1.2"
18+
"@types/node": "^18.7.15",
19+
"@types/react": "^18.0.18",
20+
"typescript": "^4.8.2"
1921
}
2022
}

‎examples/with-mobx-state-tree/pages/_app.js

-12
This file was deleted.

‎examples/with-mobx-state-tree/pages/index.js

-5
This file was deleted.

‎examples/with-mobx-state-tree/pages/other.js

-5
This file was deleted.

‎examples/with-mobx-state-tree/pages/ssg.js

-17
This file was deleted.

‎examples/with-mobx-state-tree/pages/ssr.js

-18
This file was deleted.

‎examples/with-mobx-state-tree/store.js

-52
This file was deleted.

‎examples/with-mobx-state-tree-typescript/tsconfig.json ‎examples/with-mobx-state-tree/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
1515
"jsx": "preserve",
16-
"experimentalDecorators": true
16+
"incremental": true
1717
},
1818
"exclude": ["node_modules"],
1919
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]

0 commit comments

Comments
 (0)
Please sign in to comment.