Skip to content

Commit 9725f14

Browse files
authored
Merge pull request #553 from kulchanbinod/react-search-bar-updates
Tailwind prerequisites added and reason behind debounce
2 parents 919b91b + 5b495a0 commit 9725f14

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

posts/2022-10-29-react-search-bar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ In the long-running war of frontend frameworks, React looks like it has won the
4646

4747
Before getting hands dirty with the code below are some requisites:
4848

49-
1. Any prior experience with React.js would be helpful
49+
1. Any prior experience with React.js and Tailwind CSS would be helpful
5050
1. Previous knowledge of working with Git and GitHub will be beneficial
5151
1. A general understanding of how APIs work and are called from React.js would be needed.
5252
1. Knowing about some React concepts like props, [function components](https://reactjs.org/docs/components-and-props.html#function-and-class-components), use effect hook, and fragments will be useful.
@@ -199,7 +199,7 @@ It uses React’s [useEffect hook](https://reactjs.org/docs/hooks-effect.html)
199199

200200
Next, the `updateKeyword` function is defined which filters out stories based on the keyword existing in the story’s title and author. It filters stories from all stories so that each search is done on the full set of stories, not a filtered subset. Then it sets the filtered stories as stories that will be rendered by the `HackerNewsStories` component. It also updates the keyword that will be passed in and displayed on the input box by the `SearchBar` component.
201201

202-
After that, the `SearchBar` component is added on line 45. Here you pass in the `keyword` variable and `updatedKeyword` function as `onChange so that the component works as intended.
202+
After that, the `SearchBar` component is added on line 52. Here you pass in the `keyword` variable and `updatedKeyword` function as `onChange` so that the component works as intended. If this filter triggers API calls on every onChange event, you can implement [debounce or throttle](https://www.developerway.com/posts/debouncing-in-react) techniques to reduce the number of requests sent to the API.
203203

204204
One thing to notice here is, because there are multiple elements returned by this component it is wrapped into a [React fragment](/blog/2023/02/react-fragments/) with its [short syntax](https://reactjs.org/docs/fragments.html#short-syntax). Without this wrapping, it will throw an `Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.` error. After this integration, the search functionality will work.
205205

0 commit comments

Comments
 (0)