I would like to know how to set or unset a parameter in the router.query.
In the example I have 2 check boxes, when I toggle a I want the query value a to toggle and when I toggle b I want the query value b to toggle.
This is the example code:
import { useState, useEffect } from "react";
import { withRouter } from "next/router";
import Layout from "../components/Layout";
const Test = ({ router }) => {
const [query, setQuery] = useState(router.query);
const changeQuery = val => e =>
setQuery({ ...query, [val]: e.target.checked });
const { a, b } = query;
useEffect(() => {
//what do I do here to set query param?
}, [a, b]);
return (
<Layout>
<pre>{JSON.stringify(router.query, undefined, 2)}</pre>
a:
<input
type="checkbox"
value="a"
checked={a}
onChange={changeQuery("a")}
/>
b:
<input
type="checkbox"
value="b"
checked={b}
onChange={changeQuery("b")}
/>
</Layout>
);
};
export default withRouter(Test);