Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Move patternsRef.current into filteredPatterns #16

Merged
merged 6 commits into from
Jan 19, 2023

Conversation

kienstra
Copy link
Contributor

  • Moves search filtering to ThemePatterns, higher in the component tree structure
  • Remove the need for useEffect()


const patternsRef = useRef( themePatterns );
const filteredPatterns = searchTerm.trim()
Copy link
Contributor Author

@kienstra kienstra Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filteredPatterns is like patternsRef.current

Ideally, filteredPatterns would also filter by category here, like how PatternGrid does that.

className="pattern-search"
value={ searchInput }
onChange={ ( searchTerm ) => {
const matchedPatterns = Object.keys(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is just moved to ThemePatterns/index.tsx

@kienstra kienstra changed the title Move search filtering to ThemePatterns Move patternsRef.current into filteredPatterns Jan 19, 2023
@kienstra kienstra marked this pull request as ready for review January 19, 2023 16:46
@kienstra
Copy link
Contributor Author

This PR probably needs cleanup, but you get the idea 😄

@mike-day
Copy link
Contributor

This is awesome! The intent is clearer, we should absolutely use this idea.

@kienstra
Copy link
Contributor Author

kienstra commented Jan 19, 2023

Thanks so much!

Haha, React state is so hard, it doesn't have a good notion of derived or computed state.

@mike-day mike-day merged commit b0c71c2 into add/patterns-search Jan 19, 2023
@mike-day mike-day deleted the suggestion/add/patterns-search branch January 19, 2023 17:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants