generated from TkachenkoKaterina/goit-react-hw-06-phonebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b2062d
commit 63bc5b6
Showing
7 changed files
with
52 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
// import PropTypes from 'prop-types'; | ||
import css from './Filter.module.css'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { selectFilter } from 'store/selectors'; | ||
import { updateFilter } from 'store/contactsSlice'; | ||
|
||
const Filter = () => { | ||
const dispatch = useDispatch(); | ||
const filter = useSelector(selectFilter); | ||
|
||
const handleFilterChange = e => { | ||
dispatch(updateFilter(e.target.value)); | ||
}; | ||
|
||
const Filter = ({ value, onChange }) => { | ||
return ( | ||
<div> | ||
FindContact | ||
<input | ||
className={css.input} | ||
type="text" | ||
placeholder="Search by name" | ||
value={value} | ||
onChange={onChange} | ||
value={filter} | ||
onChange={handleFilterChange} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
Filter.propTypes = { | ||
value: PropTypes.string.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
}; | ||
// Filter.propTypes = { | ||
// value: PropTypes.string.isRequired, | ||
// onChange: PropTypes.func.isRequired, | ||
// }; | ||
|
||
export default Filter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { PersistGate } from 'redux-persist/integration/react'; | ||
import { App } from 'components/App/App'; | ||
import './index.css'; | ||
import { Provider } from 'react-redux'; | ||
import { persistor, store } from './store/store'; | ||
import { store } from 'store/store'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<Provider store={store}> | ||
<PersistGate loading={null} persistor={persistor}> | ||
<App /> | ||
</PersistGate> | ||
<App /> | ||
</Provider> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
|
||
export const selectContacts = state => state.contacts.contacts.items; | ||
|
||
export const selectIsLoading = state => state.contacts.contacts.isLoading; | ||
|
||
export const selectError = state => state.contacts.contacts.error; | ||
|
||
export const selectFilter = state => state.contacts.filter; | ||
|
||
export const selectFilteredContacts = createSelector( | ||
[selectContacts, selectFilter], | ||
(contacts, filter) => { | ||
return contacts.filter(contact => | ||
contact.name.toLowerCase().includes(filter.toLowerCase()) | ||
); | ||
} | ||
); |