Support for standard schema on hooks like useList #7413
Replies: 1 comment 2 replies
|
Great idea, and the timing is good for this! const PostSchema = z.object({ const { data } = useList({ schema: PostSchema, resource: "posts" }); Under the hood, refine could call schema["~standard"].validate(record) on each item and either throw/warn on validation failure or strip unknown keys, depending on a configurable onValidationError option. |
Uh oh!
There was an error while loading. Please reload this page.
I'm not entirely sure how this implementation would look like, but I do think it would be cool if I could just pass a schema and the hook automatically spits out the data as usual, but now validated against the schema and typed without having to pass a type generic.
My reasoning is this, generics are nice, as long as they are correct, but we don't really have a way to validate that isn't very cumbersome. Currently I imagine that if I wanted validation it would have to be done after the fact on each implementation.
I think we could hit two birds with one stone here and somehow accept the name of the resource through the passed schema, that way we kinda get type safety on the resource as well.
Hope this makes sense. Lemme know if you like the idea if you'd like me to contribute to the implementation :D
All reactions