Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Remove legacy mobx example #40304

Merged
merged 3 commits into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/with-mobx-react-lite/.babelrc

This file was deleted.

36 changes: 0 additions & 36 deletions examples/with-mobx-react-lite/.gitignore

This file was deleted.

42 changes: 2 additions & 40 deletions examples/with-mobx-react-lite/README.md
@@ -1,41 +1,3 @@
# MobX V6 with Mobx React Lite
# MobX React Light

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 then the browser will take over. To illustrate this, the server rendered clock will have a different background color than the client one.

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

Page.js component is using the clock store to start and stop the store clock.

Clock.js component is using the clock store to read the time.

StoreProvider.js component is used to instantiate the `Store` both on the server and on the client.

Both components are using a custom hook `useStore` to pull in the `Store` from the provider.

## 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-react-lite)

[![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)

## 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-react-lite with-mobx-react-lite-app
```

```bash
yarn create next-app --example with-mobx-react-lite with-mobx-react-lite-app
```

```bash
pnpm create next-app --example with-mobx-react-lite with-mobx-react-lite-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](../with-mobx/)
28 changes: 0 additions & 28 deletions examples/with-mobx-react-lite/components/Clock.js

This file was deleted.

34 changes: 0 additions & 34 deletions examples/with-mobx-react-lite/components/Page.js

This file was deleted.

19 changes: 0 additions & 19 deletions examples/with-mobx-react-lite/package.json

This file was deleted.

9 changes: 0 additions & 9 deletions examples/with-mobx-react-lite/pages/_app.js

This file was deleted.

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

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions examples/with-mobx-react-lite/pages/ssg.js

This file was deleted.

12 changes: 0 additions & 12 deletions examples/with-mobx-react-lite/pages/ssr.js

This file was deleted.

46 changes: 0 additions & 46 deletions examples/with-mobx-react-lite/store.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/with-mobx/.babelrc

This file was deleted.

20 changes: 13 additions & 7 deletions examples/with-mobx/README.md
@@ -1,4 +1,4 @@
# MobX example
# MobX V6 with Mobx React Lite

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 @@ -8,28 +8,34 @@ To illustrate SSG and SSR, go to `/ssg` and `/ssr`, those pages are using Next.j

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.
Page.js component is using the clock store to start and stop the store clock.

Clock.js component is using the clock store to read the time.

StoreProvider.js component is used to instantiate the `Store` both on the server and on the client.

Both components are using a custom hook `useStore` to pull in the `Store` from the provider.

## 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)
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)

[![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)
[![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)

## 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 with-mobx-app
npx create-next-app --example with-mobx-react-lite with-mobx-react-lite-app
```

```bash
yarn create next-app --example with-mobx with-mobx-app
yarn create next-app --example with-mobx-react-lite with-mobx-react-lite-app
```

```bash
pnpm create next-app --example with-mobx with-mobx-app
pnpm create next-app --example with-mobx-react-lite with-mobx-react-lite-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)).
14 changes: 10 additions & 4 deletions examples/with-mobx/components/Clock.js
@@ -1,8 +1,13 @@
import { observer } from 'mobx-react'
const Clock = observer((props) => {
import { observer } from 'mobx-react-lite'
import { useStore } from './StoreProvider'

const Clock = observer(function Clock(props) {
// use store from the store context
const store = useStore()

return (
<div className={props.light ? 'light' : ''}>
{props.timeString}
<div className={store.light ? 'light' : ''}>
{store.timeString}
<style jsx>{`
div {
padding: 15px;
Expand All @@ -19,4 +24,5 @@ const Clock = observer((props) => {
</div>
)
})

export default Clock