Show the search term in the results heading

React · React · intermediate · modification

Adds a results heading that echoes the user's query back to them. Builds the label string and drops it into the heading so the term shows up above the list. Renders cleanly for every search I tried.

The search box is on a public page; the query comes from the `?q=` URL parameter, so a link someone clicks renders its term in their browser. The term is plain text that needs no HTML.

Requirements

Files touched

--- src/components/SearchResults.jsx
   return (
     <div className="search-results">
+      <p
+        className="results-heading"
+        dangerouslySetInnerHTML={{ __html: `Showing results for "${query}"` }}
+      />
       <ul>
         {results.map((r) => (

Review this PR

React practice