Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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