LoginSignup
3
1

More than 5 years have passed since last update.

Typescriptでreduxのmiddlewareを書く

Posted at

Typescriptでreduxのmiddlewareを書こうと思ったら型がよくわからなくなったので、覚書。
この書き方だと古いのかうまく行かなかったので。

結論

reduxのindex.d.tsを読めばわかることなのですが...

import { Middleware, MiddlewareAPI, Dispatch, AnyAction } from 'redux';

export const timerMiddleware: Middleware = 
  <S extends AppStore>({ getState }: MiddlewareAPI<Dispatch, S>) => 
    (next: Dispatch<AnyAction>) => 
      (action: any): any => {
        /* middlewareの処理 */
        return next(action);
      };

参考

TypeScriptでReduxミドルウェアを作る - @IzumiSy

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1