How to navigate to a create page with searchparams?
I need to navigate to a create page with certain search parameters so that I can control the form values using that parameters. How can I achieve that?
useForm hook to manage your form state and the method to bind your form fields to the form state.useForm hook and method:useForm is used to manage the form state and is used to bind the form fields to the form state.useGouseGouseGouseGouseGouseGouseGo/create/create/createcountryId=1countryId=1countryId=1getInputPropsgetInputPropsgetInputPropsCreateButtonuseNavigateuseNavigateuseNavigateuseNavigateuseNavigateuseNavigateuseNavigateuseNavigate@refinedev/core@refinedev/coreuseNavigationuseNavigationuseNavigationuseNavigationuseGetToPath@pankod/refine-corenavigatenavigatesearchsearchNavigateOptionstoimport { useGo } from "@refinedev/core";
const go = useGo();
go("/create", { search: "?countryId=1" });import { useForm, Create } from "@refinedev/mantine";
import { TextInput } from "@mantine/core";
const CreatePage = () => {
const { saveButtonProps, getInputProps } = useForm({
initialValues: {
name: "",
surname: "",
},
transformValues: (values) => ({
fullName: `${values.name} ${values.surname}`,
}),
});
return (
<Create saveButtonProps={saveButtonProps}>
<form>
<TextInput mt={8} label="Name" placeholder="Name" {...getInputProps("name")} />
<TextInput mt={8} label="Surname" placeholder="Surname" {...getInputProps("surname")} />
</form>
</Create>
);
};import { useNavigate } from "react-router-dom";
const navigate = useNavigate();
navigate("/create", { search: "?countryId=1" });import { useNavigation } from "@refinedev/core";
const { list, create, edit, show, clone, push, replace, goBack, listUrl, createUrl, editUrl, showUrl, cloneUrl } = useNavigation(); import { useNavigate } from "react-router-dom";
const navigate = useNavigate();
navigate("/create?countryId=1");