Skip to content

Commit 74c08da

Browse files
committed
Added support for react-router v6 and redux-react-router for connected router
1 parent f90c2e1 commit 74c08da

33 files changed

+38921
-66405
lines changed

Diff for: README.md

+36-27
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ Can be imported in various layers receiving or sending redux actions like: reduc
12571257
import { StateType, ActionType } from 'typesafe-actions';
12581258

12591259
declare module 'MyTypes' {
1260-
export type Store = StateType<typeof import('./index').default>;
1260+
export type Store = StateType<typeof import('./store').default>;
12611261
export type RootAction = ActionType<typeof import('./root-action').default>;
12621262
export type RootState = StateType<ReturnType<typeof import('./root-reducer').default>>;
12631263
}
@@ -1279,20 +1279,16 @@ When creating a store instance we don't need to provide any additional types. It
12791279
12801280
```tsx
12811281
import { RootAction, RootState, Services } from 'MyTypes';
1282-
import { createStore, applyMiddleware } from 'redux';
1282+
import { applyMiddleware, createStore } from 'redux';
12831283
import { createEpicMiddleware } from 'redux-observable';
1284-
import { createBrowserHistory } from 'history';
1285-
import { routerMiddleware as createRouterMiddleware } from 'connected-react-router';
12861284

1287-
import { composeEnhancers } from './utils';
1288-
import rootReducer from './root-reducer';
1289-
import rootEpic from './root-epic';
12901285
import services from '../services';
1286+
import { routerMiddleware } from './redux-router';
1287+
import rootEpic from './root-epic';
1288+
import rootReducer from './root-reducer';
1289+
import { composeEnhancers } from './utils';
12911290

1292-
// browser history
1293-
export const history = createBrowserHistory();
1294-
1295-
export const epicMiddleware = createEpicMiddleware<
1291+
const epicMiddleware = createEpicMiddleware<
12961292
RootAction,
12971293
RootAction,
12981294
RootState,
@@ -1301,8 +1297,6 @@ export const epicMiddleware = createEpicMiddleware<
13011297
dependencies: services,
13021298
});
13031299

1304-
const routerMiddleware = createRouterMiddleware(history);
1305-
13061300
// configure middlewares
13071301
const middlewares = [epicMiddleware, routerMiddleware];
13081302
// compose enhancers
@@ -1312,7 +1306,11 @@ const enhancer = composeEnhancers(applyMiddleware(...middlewares));
13121306
const initialState = {};
13131307

13141308
// create store
1315-
const store = createStore(rootReducer(history), initialState, enhancer);
1309+
const store = createStore(
1310+
rootReducer,
1311+
initialState,
1312+
enhancer
1313+
);
13161314

13171315
epicMiddleware.run(rootEpic);
13181316

@@ -1366,7 +1364,7 @@ export const payloadCreatorAction = createAction(
13661364
<details><summary><i>Click to expand</i></summary><p>
13671365
13681366
```tsx
1369-
import store from '../../store';
1367+
import { store } from '../../store/';
13701368
import { countersActions as counter } from '../counters';
13711369

13721370
// store.dispatch(counter.increment(1)); // Error: Expected 0 arguments, but got 1.
@@ -1856,20 +1854,31 @@ We have recommended `tsconfig.json` that you can easily add to your project than
18561854
18571855
```tsx
18581856
{
1859-
"extends": "./node_modules/react-redux-typescript-scripts/tsconfig.json",
1857+
"compilerOptions": {
1858+
"target": "ES6",
1859+
"lib": [
1860+
"dom",
1861+
"dom.iterable",
1862+
"esnext"
1863+
],
1864+
"allowJs": true,
1865+
"skipLibCheck": true,
1866+
"esModuleInterop": true,
1867+
"allowSyntheticDefaultImports": true,
1868+
"strict": true,
1869+
"forceConsistentCasingInFileNames": true,
1870+
"noFallthroughCasesInSwitch": true,
1871+
"module": "esnext",
1872+
"moduleResolution": "node",
1873+
"resolveJsonModule": true,
1874+
"isolatedModules": true,
1875+
"noEmit": true,
1876+
"jsx": "react-jsx"
1877+
},
18601878
"include": [
18611879
"src",
18621880
"typings"
1863-
],
1864-
"exclude": [
1865-
],
1866-
"compilerOptions": {
1867-
"module": "ESNext",
1868-
"target": "ESNext",
1869-
"moduleResolution": "Node",
1870-
"jsx": "preserve",
1871-
"strict": true
1872-
}
1881+
]
18731882
}
18741883

18751884
```
@@ -1916,7 +1925,7 @@ module.exports = {
19161925
root: true,
19171926
parser: '@typescript-eslint/parser',
19181927
plugins: ['@typescript-eslint'],
1919-
extends: ['react-app', 'prettier'],
1928+
extends: ['react-app', 'react-app/jest', 'prettier'],
19201929
rules: { 'import/no-anonymous-default-export': 0 },
19211930
};
19221931

Diff for: README_SOURCE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ Can be imported in various layers receiving or sending redux actions like: reduc
514514
When creating a store instance we don't need to provide any additional types. It will set-up a **type-safe Store instance** using type inference.
515515
> The resulting store instance methods like `getState` or `dispatch` will be type checked and will expose all type errors
516516
517-
::codeblock='playground/src/store/index.ts'::
517+
::codeblock='playground/src/store/store.ts'::
518518
519519
---
520520

Diff for: package-lock.json

+81-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+4
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
"hooks": {
1818
"pre-push": "npm run ci-check && npm run is-git-status-clean "
1919
}
20+
},
21+
"dependencies": {
22+
"react": "18.1.0",
23+
"react-dom": "18.1.0"
2024
}
2125
}

Diff for: playground/.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
44
plugins: ['@typescript-eslint'],
5-
extends: ['react-app', 'prettier'],
5+
extends: ['react-app', 'react-app/jest', 'prettier'],
66
rules: { 'import/no-anonymous-default-export': 0 },
77
};

0 commit comments

Comments
 (0)