React-query admin wrapper and possibily undefined value with useGetOne

オープン
#7,840 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
react, typescript
領域
frontend

調査の方向性

packages/ra-core/src/dataProvider/useGetOne.ts と packages/ra-core/src/types.ts の identifier type から始め、次にそれらの型定義を React Query の enabled オプションと比較します。query が無効な場合に hook が undefined の id を表現できることを確認し、関連する type checks または tests で、その結果生じる型の挙動を検証します。

索引モデルが issue の本文から書いたものです。

説明

TypeScript

According to the React Query documentation, we have the possibility to block the running query thanks to the enabled function if one of our parameter is not defined.
On the documentation sample, we can see userId can be set on the query definition without any issue.

We also have the possibility to use this option from the useGetOne hooks as you specified on the code doc block

https://github.com/marmelab/react-admin/blob/69d1cd1af77a432e2d1a3c2215ee93a2dedcd4be/packages/ra-core/src/dataProvider/useGetOne.ts#L26

However, the typing of the function requires the id to be a valid identifier:

https://github.com/marmelab/react-admin/blob/1ddb1672fe323baffb80567c890c759b3cea379c/packages/ra-core/src/types.ts#L139

Because of that, we have to cheat by casting the typing of the undefined value, for example:

const { data: userData } = useGetOne<UserRecord>('users', { id: userId || '' }, { enabled: !!userId });

According to me, we should make that param optional to match the react-query implementation.

What do you think?

主要言語
TypeScript
スター
27k
フォーク
5.5k
平均マージ
1日 3分
マージ済み PR(30日)
32

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

marmelab/react-admin のほかの issue

marmelab/react-admin の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。