Guest User

Untitled

a guest
Nov 30th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // контекст
  2.  
  3. const SearchState = props => {
  4.   const initialState = {
  5.     location: {
  6.       value: '',
  7.       isEnabled: false
  8.     },
  9.     language: {
  10.       value: '',
  11.       isEnabled: false
  12.     },
  13.     repos: {
  14.       value: 1,
  15.       isEnabled: false
  16.     }
  17.   };
  18.  
  19.   const [state, dispatch] = useReducer(SearchReducer, initialState);
  20.  
  21. const getLocation = () => {
  22.     return state.location;
  23.   };
  24.  
  25. // компонент
  26. const FilterLocation = () => {
  27.   const searchContext = useContext(SearchContext);
  28.   const location = searchContext.getLocation();
  29.  
  30.   const locationOnChange = e => {
  31.     // setFilters({ ...filters, location: e.target.value });
  32.     searchContext.setLocation(e.target.value);
  33.   };
  34.  
  35.   return (
  36.     <label
  37.       className={`filter location-filter ${
  38.         location.isEnabled ? 'filter-active' : 'filter-disabled'
  39.       }`}
  40.       filter='location'
  41.       htmlFor='location'
  42.     >
  43.       <FilterTitle name={'location'} isChecked={location.isEnabled} />
  44.       <input
  45.         disabled={!location.isEnabled}
  46.         type='text'
  47.         id='location-value'
  48.         name='location-value'
  49.         placeholder='Location...'
  50.         onChange={locationOnChange}
  51.         // disabled
  52.         value={location.value}
  53.       />
  54.     </label>
  55.   );
  56. };
Advertisement
Add Comment
Please, Sign In to add comment