Skip to content

Instantly share code, notes, and snippets.

@erudenko
Last active May 7, 2025 07:13
Show Gist options
  • Select an option

  • Save erudenko/0e7b8f3c53f646777c707ff1b1b1ef9e to your computer and use it in GitHub Desktop.

Select an option

Save erudenko/0e7b8f3c53f646777c707ff1b1b1ef9e to your computer and use it in GitHub Desktop.
SearchResult.tsx
import { useEffect, useState } from 'react';
interface Props {
query: string;
title: string;
}
export const BadComponent = ({ query, title }: Props) => {
const [results, setResults] = useState<string[]>([]);
const [capitalised, setCapitalised] = useState('');
useEffect(() => {
fetch(`/api/search?q=${encodeURIComponent(query)}`)
.then(r => r.json())
.then(setResults)
.catch(console.error);
}, [query, results]);
useEffect(() => {
setCapitalised(title.toUpperCase());
}, [title]);
return (
<>
<h1>{capitalised}</h1>
<ul>
{results.map((r, index) => <li key={index}>{r}</li>)}
</ul>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment