Skip to content

Commit

Permalink
fix: Avoid undefined value in <SanityPreview> (#18)
Browse files Browse the repository at this point in the history
* Set apiVersion on client if supported

* Use version 1

* Fix bug where column select of ref would throw exception before value was set
  • Loading branch information
runeb authored Jun 25, 2021
1 parent 82e1cae commit 1ca327a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function Cell({ field, value }: Props) {
default: {
return (
<td key={field.name}>
<SanityPreview type={field.type} layout="default" value={value} />
{value && (
<SanityPreview type={field.type} layout="default" value={value} />
)}
</td>
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import _client from 'part:@sanity/base/client';
const client = _client as import('@sanity/client').SanityClient;
const sanityClient = _client as import('@sanity/client').SanityClient;
let client = sanityClient

if (typeof sanityClient.withConfig === 'function') {
client = sanityClient.withConfig({
apiVersion: "1"
})
}

export default client;

0 comments on commit 1ca327a

Please sign in to comment.