>
);
diff --git a/src/pages/newsArticle.tsx b/src/pages/newsArticle.tsx
index 1f12618..6f190a2 100644
--- a/src/pages/newsArticle.tsx
+++ b/src/pages/newsArticle.tsx
@@ -1,38 +1,39 @@
import React from 'react';
import { Link, useParams } from 'react-router-dom';
import Hero from '../components/Hero';
-import useQuery from '../hooks/useQuery';
import imageUrl from '../imageUrl';
import BlockContent from '@sanity/block-content-to-react';
+import sanity from '../sanity';
import '../css/article.css';
export default function NewsArticle() {
let { articleId } = useParams<{ articleId: string }>();
- let article = useQuery('*[_id == $articleId] [0]', {
- articleId,
- });
+ let [article, setArticle] = React.useState(null!);
- let thumbUrl: string | undefined = undefined;
+ React.useEffect(() => {
+ sanity.fetch('*[_id == $articleId] [0]', { articleId }).then(setArticle);
+ }, [articleId]);
+
+ let thumbUrl: string | null = null;
if (article?.thumbnail) {
- thumbUrl = imageUrl(article.thumbnail).url() || undefined;
+ thumbUrl = imageUrl(article.thumbnail).url();
} else {
thumbUrl = '/images/hero.png';
}
return (
<>
-
+
-
- Go to all news articles
-
-
{article ? (
+
+ Go to all news articles
+
{article.title}
- {article.publish_date}
-
- {article.author || 'No author'}
+
+ Posted {article.publish_date} by {article.author || 'No author'}
+
{/* Wrap the BlockContent in a div because it expands to <>> */}