Last active
May 7, 2025 07:13
-
-
Save erudenko/0e7b8f3c53f646777c707ff1b1b1ef9e to your computer and use it in GitHub Desktop.
SearchResult.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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