📜  createSearchParams - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:25.128000             🧑  作者: Mango

代码示例2
// React Router v6: hook reads/modifies current location URL query str
import { useSearchParams } from 'react-router-dom'

function App() {
  let [searchParams, setSearchParams] = useSearchParams()

  const handleSubmit = e => {
    e.preventDefault()
    let params = serializeFormQuery(e.target)
      // assume 'serializeFormQuery()' creates an obj of { key: value }
      // pairs from fields in the form that make up the query
    setSearchParams(params)
  }

  return (
    
{/* ... */}
); }