Skip to content

Commit

Permalink
fix deprecated configureStore in with-redux-saga example (#50342)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

This PR introduces the following changes:
- Replaced redux's [deprecated
createStore](reduxjs/redux#4336) with
configureStore from @reduxjs/toolkit.
- Updated packages.
- Corrected an error in getStaticProps.

This is my first contribution and there may be some shortcomings, I
appreciate your understanding and look forward to your feedback.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
kijikunnn and ijjk committed Jun 14, 2023
1 parent 6f9c9ad commit d080c8e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
9 changes: 5 additions & 4 deletions examples/with-redux-saga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"start": "next start"
},
"dependencies": {
"@reduxjs/toolkit": "^1.9.5",
"next": "latest",
"next-redux-wrapper": "^6.0.2",
"next-redux-wrapper": "^8.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "7.2.0",
"redux": "4.0.5",
"redux-saga": "1.1.3"
"react-redux": "8.0.5",
"redux": "4.2.1",
"redux-saga": "1.2.3"
},
"devDependencies": {
"redux-devtools-extension": "^2.13.8"
Expand Down
19 changes: 11 additions & 8 deletions examples/with-redux-saga/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ const Index = () => {
return <Page title="Index Page" linkTo="/other" NavigateTo="Other Page" />
}

export const getStaticProps = wrapper.getStaticProps(async ({ store }) => {
store.dispatch(tickClock(false))
export const getStaticProps = wrapper.getStaticProps(
(store) =>
async ({ params }) => {
await store.dispatch(tickClock(false))

if (!store.getState().placeholderData) {
store.dispatch(loadData())
store.dispatch(END)
}
if (!store.getState().placeholderData) {
await store.dispatch(loadData())
store.dispatch(END)
}

await store.sagaTask.toPromise()
})
await store.sagaTask.toPromise()
}
)

export default Index
9 changes: 6 additions & 3 deletions examples/with-redux-saga/pages/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ const Other = () => {
return <Page title="Other Page" linkTo="/" NavigateTo="Index Page" />
}

export const getStaticProps = wrapper.getStaticProps(async ({ store }) => {
store.dispatch(tickClock(false))
})
export const getStaticProps = wrapper.getStaticProps(
(store) =>
async ({ params }) => {
await store.dispatch(tickClock(false))
}
)

export default Other
10 changes: 8 additions & 2 deletions examples/with-redux-saga/store.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { applyMiddleware, createStore } from 'redux'
import { applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { createWrapper } from 'next-redux-wrapper'

import rootReducer from './reducer'
import rootSaga from './saga'
import { configureStore } from '@reduxjs/toolkit'

const bindMiddleware = (middleware) => {
if (process.env.NODE_ENV !== 'production') {
Expand All @@ -15,7 +16,12 @@ const bindMiddleware = (middleware) => {

export const makeStore = (context) => {
const sagaMiddleware = createSagaMiddleware()
const store = createStore(rootReducer, bindMiddleware([sagaMiddleware]))
const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({ thunk: false }).concat(sagaMiddleware),
enhancers: [bindMiddleware([sagaMiddleware])],
})

store.sagaTask = sagaMiddleware.run(rootSaga)

Expand Down

0 comments on commit d080c8e

Please sign in to comment.