Skip to content

Commit 155a4d5

Browse files
authored
[Docs] Remove legacy mobx example (vercel#40304)
## Info This PR merges with-mobx-lite into with-mobx. After that we will migrate `with-mobx` to typescript. ## 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 eadaca7 commit 155a4d5

File tree

20 files changed

+75
-344
lines changed

20 files changed

+75
-344
lines changed

Diff for: examples/with-mobx-react-lite/.babelrc

-4
This file was deleted.

Diff for: examples/with-mobx-react-lite/.gitignore

-36
This file was deleted.

Diff for: examples/with-mobx-react-lite/README.md

+2-40
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
1-
# MobX V6 with Mobx React Lite
1+
# MobX React Light
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 then the browser will take over. To illustrate this, the server rendered clock will have a different background color than the client one.
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-
Page.js component is using the clock store to start and stop the store clock.
12-
13-
Clock.js component is using the clock store to read the time.
14-
15-
StoreProvider.js component is used to instantiate the `Store` both on the server and on the client.
16-
17-
Both components are using a custom hook `useStore` to pull in the `Store` from the provider.
18-
19-
## Deploy your own
20-
21-
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-react-lite)
22-
23-
[![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-react-lite&project-name=with-mobx-react-lite&repository-name=with-mobx-react-lite)
24-
25-
## How to use
26-
27-
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:
28-
29-
```bash
30-
npx create-next-app --example with-mobx-react-lite with-mobx-react-lite-app
31-
```
32-
33-
```bash
34-
yarn create next-app --example with-mobx-react-lite with-mobx-react-lite-app
35-
```
36-
37-
```bash
38-
pnpm create next-app --example with-mobx-react-lite with-mobx-react-lite-app
39-
```
40-
41-
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](../with-mobx/)

Diff for: examples/with-mobx-react-lite/components/Clock.js

-28
This file was deleted.

Diff for: examples/with-mobx-react-lite/components/Page.js

-34
This file was deleted.

Diff for: examples/with-mobx-react-lite/package.json

-19
This file was deleted.

Diff for: examples/with-mobx-react-lite/pages/_app.js

-9
This file was deleted.

Diff for: examples/with-mobx-react-lite/pages/index.js

-5
This file was deleted.

Diff for: examples/with-mobx-react-lite/pages/other.js

-5
This file was deleted.

Diff for: examples/with-mobx-react-lite/pages/ssg.js

-11
This file was deleted.

Diff for: examples/with-mobx-react-lite/pages/ssr.js

-12
This file was deleted.

Diff for: examples/with-mobx-react-lite/store.js

-46
This file was deleted.

Diff for: examples/with-mobx/.babelrc

-7
This file was deleted.

Diff for: examples/with-mobx/README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MobX example
1+
# MobX V6 with Mobx React Lite
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

@@ -8,28 +8,34 @@ To illustrate SSG and SSR, go to `/ssg` and `/ssr`, those pages are using Next.j
88

99
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`.
1010

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.
11+
Page.js component is using the clock store to start and stop the store clock.
12+
13+
Clock.js component is using the clock store to read the time.
14+
15+
StoreProvider.js component is used to instantiate the `Store` both on the server and on the client.
16+
17+
Both components are using a custom hook `useStore` to pull in the `Store` from the provider.
1218

1319
## Deploy your own
1420

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)
21+
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-react-lite)
1622

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&project-name=with-mobx&repository-name=with-mobx)
23+
[![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-react-lite&project-name=with-mobx-react-lite&repository-name=with-mobx-react-lite)
1824

1925
## How to use
2026

2127
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:
2228

2329
```bash
24-
npx create-next-app --example with-mobx with-mobx-app
30+
npx create-next-app --example with-mobx-react-lite with-mobx-react-lite-app
2531
```
2632

2733
```bash
28-
yarn create next-app --example with-mobx with-mobx-app
34+
yarn create next-app --example with-mobx-react-lite with-mobx-react-lite-app
2935
```
3036

3137
```bash
32-
pnpm create next-app --example with-mobx with-mobx-app
38+
pnpm create next-app --example with-mobx-react-lite with-mobx-react-lite-app
3339
```
3440

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

Diff for: examples/with-mobx/components/Clock.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { observer } from 'mobx-react'
2-
const Clock = observer((props) => {
1+
import { observer } from 'mobx-react-lite'
2+
import { useStore } from './StoreProvider'
3+
4+
const Clock = observer(function Clock(props) {
5+
// use store from the store context
6+
const store = useStore()
7+
38
return (
4-
<div className={props.light ? 'light' : ''}>
5-
{props.timeString}
9+
<div className={store.light ? 'light' : ''}>
10+
{store.timeString}
611
<style jsx>{`
712
div {
813
padding: 15px;
@@ -19,4 +24,5 @@ const Clock = observer((props) => {
1924
</div>
2025
)
2126
})
27+
2228
export default Clock

0 commit comments

Comments
 (0)