Skip to content

Commit 861252b

Browse files
committed
pass in context state into component
1 parent dcb15ea commit 861252b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/Components/Filters/Search.jsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23

34
import Styles from './Search.styles.scss';
45
import { useNetwork } from '../../state/network/Context';
56

6-
const Search = () => {
7-
const { state, actions } = useNetwork();
8-
const search = state.get('search');
7+
const Search = ({ name, value }) => {
8+
const { actions } = useNetwork();
99

1010
const handleInputChange = ({ target }) => {
1111
actions.updateSearch({
12-
name: search.name,
12+
name,
1313
value: target.value,
1414
});
1515
};
@@ -20,9 +20,18 @@ const Search = () => {
2020
onChange={handleInputChange}
2121
placeholder="Search by full URL"
2222
type="text"
23-
value={search.value}
23+
value={value}
2424
/>
2525
);
2626
};
2727

28+
Search.propTypes = {
29+
name: PropTypes.string.isRequired,
30+
value: PropTypes.string,
31+
};
32+
33+
Search.defaultProps = {
34+
value: '',
35+
};
36+
2837
export default Search;

src/Containers/FilterContainer.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const FilterContainer = () => {
2222
return (
2323
<section className={Styles['filters-container']}>
2424
<div className={Styles['filter-row']}>
25-
<Search />
25+
<Search {...state.get('search')} />
2626
</div>
2727

2828
<div className={Styles['type-filter-row']}>

0 commit comments

Comments
 (0)