Skip to content

Commit 01e31c0

Browse files
EskiMojo14ben.durrant
andauthored
update README and types to match named export (#347)
* attach withExtraArgument as per README and types * change back to named export and fix types/README instead * attach -> export --------- Co-authored-by: ben.durrant <ben.durrant@actual-experience.com>
1 parent f41f21c commit 01e31c0

File tree

4 files changed

+6
-17
lines changed

4 files changed

+6
-17
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,10 @@ function fetchUser(id) {
133133
}
134134
```
135135

136-
If you're setting up the store by hand, the default `thunk` export has an attached `thunk.withExtraArgument()` function that should be used to generate the correct thunk middleware:
136+
If you're setting up the store by hand, the named export `withExtraArgument()` function should be used to generate the correct thunk middleware:
137137

138138
```js
139-
const store = createStore(
140-
reducer,
141-
applyMiddleware(thunk.withExtraArgument(api))
142-
)
139+
const store = createStore(reducer, applyMiddleware(withExtraArgument(api)))
143140
```
144141

145142
## Why Do I Need This?

src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,7 @@ function createThunkMiddleware<
3636
return middleware
3737
}
3838

39-
export const thunk = createThunkMiddleware() as ThunkMiddleware & {
40-
withExtraArgument<
41-
ExtraThunkArg,
42-
State = any,
43-
BasicAction extends Action = AnyAction
44-
>(
45-
extraArgument: ExtraThunkArg
46-
): ThunkMiddleware<State, BasicAction, ExtraThunkArg>
47-
}
39+
export const thunk = createThunkMiddleware()
4840

4941
// Export the factory function so users can create a customized version
5042
// with whatever "extra arg" they want to inject into their thunks

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export type ThunkActionDispatch<
7878
* @template State The redux state
7979
* @template BasicAction The (non-thunk) actions that can be dispatched
8080
* @template ExtraThunkArg An optional extra argument to pass to a thunk's
81-
* inner function. (Only used if you call `thunk.withExtraArgument()`)
81+
* inner function. (Only used if you call `withExtraArgument()`)
8282
*/
8383
export type ThunkMiddleware<
8484
State = any,

typescript_test/typescript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { applyMiddleware, bindActionCreators, createStore } from 'redux'
33
import type { Action, AnyAction } from 'redux'
44

5-
import { thunk } from '../src/index'
5+
import { thunk, withExtraArgument } from '../src/index'
66
import type {
77
ThunkAction,
88
ThunkActionDispatch,
@@ -70,7 +70,7 @@ store.dispatch(testGetState())
7070
const storeThunkArg = createStore(
7171
fakeReducer,
7272
applyMiddleware(
73-
thunk.withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>
73+
withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>
7474
)
7575
)
7676
storeThunkArg.dispatch({ type: 'FOO' })

0 commit comments

Comments
 (0)