Reputation:
I'm adding a search bar to a page in my movie review application. The page displays all the review posts for one specific movie. The prop "reviews" contains all the existing reviews. I was stuck with figuring out how to pass the value of the state "filteredResults" from the useSearch hook to the ReviewPost component so that I could display the filteredResults data on the page.
Reviews Card:
export const Reviews = ({ reviews }) => (
<div>
{reviews.map((review, i) => (
<div key={i}>{review}</div>
))}
</div>
)
Search Bar for the Reviews:
export const ReviewSearchBar = ({ reviews }) => {
const { onChange, textValue } = useSearch({ reviews })
return (
<div>
<input
onChange={onChange}
value={textValue}
/>
</div>
)
}
Upvotes: 1
Views: 65
Reputation: 132
You need to move const { onChange, textValue, filteredResults } = useSearch({ reviews })
to Parent component and from Parent pass props onChange, textValue
to ReviewSearchBar
and prop filteredResults
to ReviewPosts
component
Upvotes: 1