Attempted import error: 'withRouter' is not exported from 'react-router'

Viewed 767

This is the code I am using for a register screen using React:

import React, { useCallback } from "react";
import { withRouter } from "react-router";
import app from "../Firebase/firebase";

const Register = ({history}) => {
    const handleSignup = useCallback(async event => {
        event.preventDefault()
        const { email, password } = event.target.elements;
        try {
            await app
                .auth()
                .createUserWithEmailAndPassword(email.value, password.value);
            history.push("/dashboard")
        } catch(error) {
            alert(error)
        }
    }, [history]);

    return (
        <div>
            <p>Register</p>
            <Form onSubmit={handleSignup}>
                <label>
                    Email
                    <input name="email" type="email" placeholder="Email" />
                </label>
                <label>
                    Password
                    <input name="password" type="password" placeholder="Password" />
                </label>
                <button type="submit">Register</button>
            </Form>
        </div>
    )
}

export default withRouter(Register)

I am getting the error mentioned in the title, what am I doing wrong here?

I'm also getting these errors when running npm i react-routerin the terminal: npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.16.0 requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself.

1 Answers

you need to downgrade react-router and react-router-dom to version 5.

npm install react-router@5
npm install react-router-dom@5

I don't think Cube.js is maintained anymore. Probably best to find a different platform

Related