Skip to content

Commit

Permalink
update README and types to match named export (#347)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
EskiMojo14 and ben.durrant committed Apr 21, 2023
1 parent f41f21c commit 01e31c0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -133,13 +133,10 @@ function fetchUser(id) {
}
```

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:
If you're setting up the store by hand, the named export `withExtraArgument()` function should be used to generate the correct thunk middleware:

```js
const store = createStore(
reducer,
applyMiddleware(thunk.withExtraArgument(api))
)
const store = createStore(reducer, applyMiddleware(withExtraArgument(api)))
```

## Why Do I Need This?
Expand Down
10 changes: 1 addition & 9 deletions src/index.ts
Expand Up @@ -36,15 +36,7 @@ function createThunkMiddleware<
return middleware
}

export const thunk = createThunkMiddleware() as ThunkMiddleware & {
withExtraArgument<
ExtraThunkArg,
State = any,
BasicAction extends Action = AnyAction
>(
extraArgument: ExtraThunkArg
): ThunkMiddleware<State, BasicAction, ExtraThunkArg>
}
export const thunk = createThunkMiddleware()

// Export the factory function so users can create a customized version
// with whatever "extra arg" they want to inject into their thunks
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Expand Up @@ -78,7 +78,7 @@ export type ThunkActionDispatch<
* @template State The redux state
* @template BasicAction The (non-thunk) actions that can be dispatched
* @template ExtraThunkArg An optional extra argument to pass to a thunk's
* inner function. (Only used if you call `thunk.withExtraArgument()`)
* inner function. (Only used if you call `withExtraArgument()`)
*/
export type ThunkMiddleware<
State = any,
Expand Down
4 changes: 2 additions & 2 deletions typescript_test/typescript.ts
Expand Up @@ -2,7 +2,7 @@
import { applyMiddleware, bindActionCreators, createStore } from 'redux'
import type { Action, AnyAction } from 'redux'

import { thunk } from '../src/index'
import { thunk, withExtraArgument } from '../src/index'
import type {
ThunkAction,
ThunkActionDispatch,
Expand Down Expand Up @@ -70,7 +70,7 @@ store.dispatch(testGetState())
const storeThunkArg = createStore(
fakeReducer,
applyMiddleware(
thunk.withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>
withExtraArgument('bar') as ThunkMiddleware<State, Actions, string>
)
)
storeThunkArg.dispatch({ type: 'FOO' })
Expand Down

0 comments on commit 01e31c0

Please sign in to comment.