Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5066 stevensc 1
import React, { useEffect } from 'react'
1 www 2
 
5066 stevensc 3
import { useForm } from 'react-hook-form'
4
import { useLocation, useHistory } from 'react-router-dom'
5
 
1 www 6
const SearchBar = () => {
5066 stevensc 7
  const { register, handleSubmit, getValues, setValue } = useForm()
8
  const location = useLocation()
9
  const history = useHistory()
1 www 10
 
11
  useEffect(() => {
5066 stevensc 12
    const keyword = new URLSearchParams(location.search).get('keyword')
13
    setValue('keyword', keyword)
14
  }, [])
1 www 15
 
16
  const onSubmitHandler = (data, event) => {
17
    history.push({
18
      pathname: location.pathname,
5066 stevensc 19
      search: `?keyword=${getValues('keyword')}`
20
    })
21
  }
1 www 22
 
23
  return (
24
    <div className="search-sec">
25
      <div className="container">
1809 steven 26
        <div className="search-box border-gray border-radius">
1 www 27
          <form
28
            name="form-listing-search"
29
            id="form-listing-search"
30
            onSubmit={handleSubmit(onSubmitHandler)}
31
          >
32
            <input
33
              type="text"
34
              name="keyword"
35
              id="keyword"
3723 stevensc 36
              placeholder="¿Que desea encontrar?"
1 www 37
              ref={register}
38
            />
3866 stevensc 39
            <button type="submit">Buscar</button>
1 www 40
          </form>
41
        </div>
42
      </div>
43
    </div>
5066 stevensc 44
  )
45
}
1 www 46
 
5066 stevensc 47
export default SearchBar