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.

2022年前後に色々変わったReactの話

Posted at

仕様変更が結構痛いところに来たので備忘録です。

React Router 系

変更後の書き方
import { BrowserRouter, Route,Routes } from 'react-router-dom';
...
const App:React.FC = () => {
...
    return(
        <BrowserRouter>
            <Routes>
                <Route
                    path = '/'
                    element={
                        <Home />
                    }
                />
                <Route
                    path = 'about'
                    element={
                        <About />
                    }
                />
            </Routes>
        </BrowserRouter>
    );
}

useHistory -> useNavigate

変更後の書き方
import {useNavigate} from "react-router-dom";
...
const App:React.FC = () => {
    const navigate = useNavigate();
    const toabout = () => {
        navigate("/about");
    };
...
    return(
        <button onClick={toabout}>Aboutへ</button>
    );
}
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?