React-query admin wrapper and possibily undefined value with useGetOne

Aperta
#7,840 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Inizia da packages/ra-core/src/dataProvider/useGetOne.ts e dall'identifier type in packages/ra-core/src/types.ts, quindi confronta i relativi tipi con l'opzione enabled di React Query. Verifica che l'hook possa rappresentare un id undefined quando la query è disabilitata e verifica il comportamento dei tipi risultante con i type check o i test pertinenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
TypeScript
Stelle
27k
Fork
5.5k
Merge medio
1g 2h
PR unite (30g)
32

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di marmelab/react-admin

Tutte le issue di marmelab/react-admin

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.