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?

ReactでLinkを使って"Cannot destructure property 'basename' of 'React.useContext(...)' as it is null."が発生した時の対処法

Last updated at Posted at 2024-05-21

はじめに

現在Reactを学習中。
ReactでLinkを使用した際にエラーが発生したのでその対処法をまとめる。

問題

Link使用時に下記エラーが発生した。

Cannot destructure property 'basename' of 'React.useContext(...)' as it is null.

解決

LinkはReactRouterの機能のため、Linkを使用できるのは<BrowserRouter></BrowserRouter>で囲われた範囲内のみ。
というわけでBrowserRouterでAppの中身を囲ってあげると解決する。

import { BrowserRouter } from "react-router-dom";

export const App = () => {
    return (
        <BrowserRouter>
            //Linkを使用しているその他のコンポーネント
        </BrowserRouter>
    )
}
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?