rsnext/examples/with-redux-observable
JTaylor0196 f7baa56792
update example Deploy button URLs (#48842)
### What?
Updates Deploy button URLs for all listed examples here:
https://github.com/vercel/next.js/tree/canary/examples

### Why?
The Deploy URLs are currently broken and result in a failed clone
attempt on Vercel.

### How?
The URLs have been changed from https://vercel.com/new/git/external?… to
-> https://vercel.com/new/clone?…
(Last updated
[here](8eaabe2fb0)
in 2021)
2023-04-26 13:31:44 -04:00
..
components Refactor with redux observable (#13615) 2020-06-03 09:23:16 +00:00
pages Run next/link codemod for Next.js 13 on examples (#41913) 2022-10-30 21:00:45 +01:00
store Refactor with redux observable (#13615) 2020-06-03 09:23:16 +00:00
.gitignore Remove incorrect entries for pnpm debug log (#47241) 2023-03-26 22:26:05 -07:00
package.json Update Examples to use React 18 (#42027) 2022-10-28 17:43:20 +00:00
README.md update example Deploy button URLs (#48842) 2023-04-26 13:31:44 -04:00

Redux-Observable example

This example is a page that renders information about Star-Wars characters. It fetches new character every 3 seconds having the initial character fetched on a server.

Example also uses redux-logger to log every action.

Deploy your own

Deploy the example using Vercel or preview live with StackBlitz

Deploy with Vercel

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

npx create-next-app --example with-redux-observable with-redux-observable-app
yarn create next-app --example with-redux-observable with-redux-observable-app
pnpm create next-app --example with-redux-observable with-redux-observable-app

Deploy it to the cloud with Vercel (Documentation).

Note: we are not using AjaxObservable from the rxjs library; as of rxjs v5.5.6, it will not work on both the server- and client-side. Instead we call the default export from universal-rxjs-ajax (as request).

We transform the Observable we get from ajax into a Promise in order to await its resolution. That resolution should be a action (since the epic returns Observables of actions). We immediately dispatch that action to the store.

This server-side solution allows compatibility with Next. It may not be something you wish to emulate. In other situations, calling or awaiting epics directly and passing their result to the store would be an anti-pattern. You should only trigger epics by dispatching actions. This solution may not generalise to resolving more complicated sets of actions.

The layout of the redux related functionality is split between:

- actions (in `redux/actions.js`)
- actionTypes (in `redux/actionTypes.js`)
- epics (in `redux/epics.js`)
- reducer (in `redux/reducer.js`)

and organized in redux/index.js.

Excepting in those manners discussed above, the configuration is similar the configuration found in with-redux example and redux-observable docs.