LoginSignup
1
0

More than 5 years have passed since last update.

recomposeのlifecycleにcomponentDidCatchの型定義がない件

Last updated at Posted at 2019-02-13

概要

React Hooksが出たので今更recomposeの記事を書いたところで需要はないと思いますが、
割と好きなライブラリでしたし思い出として残しておきます。

recomposeが使われている既存のサービスをFlowからTypeScriptにしていたところ、
componentDidCatchが@types/recomposeにないことが分かりました。
※作業開始時はHooksがまだα版だったのでrecomposeはそのまま残しておくことにしました。

image.png

対策

import React, { ErrorInfo } from 'react';
import { lifecycle } from 'recompose';
省略
lifecycle<{}, {}, { componentDidCatch(error: Error, errorInfo: ErrorInfo): void }>({
  componentDidCatch(error, errorInfo) {
省略

こんな感じにcomponentDidCatchを追加して解決しました。

1
0
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
1
0