0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】reactのuseHistoryがエラーになる対処

Last updated at Posted at 2023-10-31

はじめに

個人開発メモ📝
react-routerを使用したく、useHistoryを書いたらエラーになった話。

useHistoryを使用してみる

npm install react-router-dom
Register.jsx
import { useHistory } from 'react-router-dom';

function RegistrationForm() {
    const history = useHistory();
    // 省略
    .then(data => {
        history.push('/login');
    })

このように書いたら、

Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/react-router-dom.js?v=2f8e3fa7' does not provide an export named 'useHistory'

このエラーメッセージがローカル上に出ました。

対処法

react-router-dom バージョン6 からは、useNavigateが推奨になったとのこと。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?