Skip to content

Commit

Permalink
docs: add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
krulod committed Nov 1, 2023
1 parent f2009e0 commit 968cc1e
Show file tree
Hide file tree
Showing 89 changed files with 13,125 additions and 52 deletions.
61 changes: 9 additions & 52 deletions docs/src/content/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,12 @@ title: Examples
description: Complex examples of Reatom state manager
---

### Base template

Vite, TypeScript, React and Reatom ecosystem, a good start point: https://github.com/artalar/reatom-react-ts/blob/main/src/features/model.ts

Try it now: [codesandbox](https://codesandbox.io/p/sandbox/github/artalar/reatom-react-ts/tree/main), [stackblitz](https://githubblitz.com/artalar/reatom-react-ts), [gitpod](https://gitpod.io/#https://github.com/artalar/reatom-react-ts)

### Data fetching and React

https://codesandbox.io/s/reatomasync-9t0x42?file=/src/model.ts

### Next.js + Reatom

A close-to-real-life example of SSR (Server-Side Rendering) with API data hydration. The cool thing is that the code is almost isomorphic. You can check [this commit](https://github.com/artalar/reatom-nextjs/commit/ca0099bcddc0fbd5bc8c76eeb160f828838453d7) to understand how simple it is to turn on SSR for an existing code with Reatom.

https://github.com/artalar/reatom-nextjs

### Migration from RTK

https://github.com/artalar/RTK-entities-basic-example/pull/1

### Search component

This example is close to real life and shows the complexity of interactive UI. It uses [async package](/package/async) to handle classic search edge cases and made perfect UX.

https://codesandbox.io/s/reatom-react-search-component-l4pe8q?file=/src/App.tsx

### Dynamic atom creation

This example shoes how to use [atomization](/recipes/atomization/) to improve editable fields performance, persists it to localStorage.

https://codesandbox.io/s/reatom-react-atomization-k39vrs?file=/src/App.tsx

### Data fetching and Svelte

https://svelte.dev/repl/0613e23e6aa74246afad6d726d6c5a33?version=3.55.0

### Tree-like dependent reactive structure

Nested checkboxes with indeterminate states could be realy hard and unoptimal in reactive context. This example shows the complex optimized model for tree-like structure, check [the model file](https://github.com/artalar/reatom-react-tree/blob/main/src/model.ts)

https://github.com/artalar/reatom-react-tree/blob/main/src/model.ts.

### Managing notifications

This example perfectly illustrates the benefits of [atomization](/recipes/atomization/) and reusability within the Reatom ecosystem - [reatom/timer](/package/timer/).

- **Domain-Oriented Code**: You don't need to normalize data, store states in separate lists, select and modify them by IDs. Instead, you can describe the entire logic in one factory, making it safer to create instances of your models. This significantly reduces and simplifies the code. While you can use classes, I prefer factories.
- **Isolated States**: Since states are highly isolated into atoms, they are also easy to use in the view layer. Take a look at App.tsx for an example.
- **Versatile Use**: reatom/timer is not limited to [Pomodoro demos](https://codesandbox.io/s/reatom-react-pomodoro-f219zu?file=/src/App.tsx), it can be used to manage the progress of just about anything. It comes with settings for update frequency and pause control out of the box.
- **A Nice Bonus**: The essence of atomization lies in state isolation, which is more performance-optimized compared to managing elements by recreating lists in Redux and Effector.

https://codesandbox.io/p/sandbox/reatom-react-notifications-krs6sr?file=/src/model.ts
- TypeScript + Vite + React + Reatom: [source](https://github.com/artalar/reatom-react-ts), [StackBlitz](https://stackblitz.com/~/github.com/artalar/reatom-react-ts)
- Next.js + Reatom: [source](https://github.com/artalar/reatom-nextjs), [StackBlitz](https://stackblitz.com/~/github.com/artalar/reatom-nextjs)
- [Svelte data fetching example](https://svelte.dev/repl/0613e23e6aa74246afad6d726d6c5a33?version=3.55.0)
- [Example of migration from Redux Toolkit to Reatom](https://github.com/artalar/RTK-entities-basic-example/pull/1)
- React data fetching example: [source](https://github.com/artalar/reatom/tree/v3/examples/react-data-fetching), [StackBlitz](https://stackblitz.com/github/artalar/reatom/tree/v3/examples/react-data-fetching)
- React search component example: [source](https://github.com/artalar/reatom/tree/v3/examples/react-search), [StackBlitz](https://stackblitz.com/github/artalar/reatom/tree/v3/examples/react-search)
- React atomization example: [source](https://github.com/artalar/reatom/tree/v3/examples/react-atomization), [StackBlitz](https://stackblitz.com/github/artalar/reatom/tree/v3/examples/react-atomization)
- React tree example: [source](https://github.com/artalar/reatom/tree/v3/examples/react-tree), [StackBlitz](https://stackblitz.com/github/artalar/reatom/tree/v3/examples/react-tree)
- React notifications example:[source](https://github.com/artalar/reatom/tree/v3/examples/react-notifications), [StackBlitz](https://stackblitz.com/github/artalar/reatom/tree/v3/examples/react-notifications)
4 changes: 4 additions & 0 deletions examples/nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["@reatom"],
"extends": ["next/core-web-vitals", "plugin:@reatom/recommended"]
}
35 changes: 35 additions & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
11 changes: 11 additions & 0 deletions examples/nextjs/.gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: npm install && npm run dev
command: npm run dev


5 changes: 5 additions & 0 deletions examples/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Reatom + Next.js example

An example showing how to use Reatom in a Next.js application.

[Open in StackBlitz](https://stackblitz.com/github/artalar/reatom/tree/v3/examples/nextjs)
6 changes: 6 additions & 0 deletions examples/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
}

module.exports = nextConfig
Loading

0 comments on commit 968cc1e

Please sign in to comment.