5

I am using below versions,

"formik": "^2.2.9"

"react": "^18.2.0"

"react-dom": "^18.2.0"

"react-router-dom": "^6.4.0"

"react-scripts": "5.0.1"

"typescript": "^4.7.4"

"web-vitals": "^2.1.4"

"@types/react-router-dom": "^5.3.3"

And below is my code

import { Field, Formik } from "formik";
import { Link } from "react-router-dom";
import { Form } from "react-router-dom";
import Button from "../movies/Button";

export default function CreateGenre(){
    //const navigate = useNavigate();
    return (
        <>
            <h3>Create Genre</h3>
            <Formik 
                initialValues={{
                    name: ''
                }}
                onSubmit={value=>{
                    console.log(value);
                }}
                >
                <Form>
                    <div className="form-group">
                        <label htmlFor="name" >Name</label>
                        <Field name="name" className="form-control" />
                    </div>
                    <Button type='submit'>Save changes</Button>
                    <Link className="button button-secondary" to="/genres">Cancel</Link> 
                </Form>   
            </Formik>
        </>
    );
}

And getting the error on runtime.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
Ari4
  • 860
  • 7
  • 12
  • 1
    Using any of the new `react-router-dom@6.4` Data API components ***requires*** them to be rendered within one of the new Data routers. See [Picking a Router](https://reactrouter.com/en/main/routers/picking-a-router). If you still need help from here can you edit the post to include how you are setting up the router and routes? – Drew Reese Oct 05 '22 at 15:49

1 Answers1

17

Your Form component is not imported correctly. An example of a correct import is shown below.

import { Field, Formik,Form } from "formik"; // <== this correct import
import { Link } from "react-router-dom";
import Button from "../movies/Button";