import React, { ReactElement } from 'react' import ReactDOM from 'react-dom' import { graphql, useStaticQuery } from 'gatsby' import PostTeaser from '../PostTeaser' import SearchResultsEmpty from './SearchResultsEmpty' import * as styles from './SearchResults.module.css' export interface Results { slug: string } const query = graphql` query SearchResults { allMarkdownRemark { edges { node { ...PostTeaser } } } } ` function SearchResultsPure({ searchQuery, results, toggleSearch, posts }: { posts: Queries.SearchResultsQuery['allMarkdownRemark']['edges'] searchQuery: string results: Results[] toggleSearch(): void }) { return (
{results.length > 0 ? ( ) : ( )}
) } export default function SearchResults({ searchQuery, results, toggleSearch }: { searchQuery: string results: Results[] toggleSearch(): void }): ReactElement { const data = useStaticQuery(query) const posts = data.allMarkdownRemark.edges // creating portal to break out of DOM node we're in // and render the results in content container return ReactDOM.createPortal( , document.getElementById('document') ) }