Telegram Group & Telegram Channel
🚀 Как избавиться от "тряски" компонентов при переключении страниц в React?

Сегодня хочу показать вам простой способ, как сделать ваш интерфейс более плавным при навигации между страницами.

Вы замечали, что при переходе между роутами компоненты "мигают" или резко перерисовываются? Особенно это бросается в глаза, когда вы используете React Router и на каждой новой странице заново монтируются одни и те же элементы (например, хедер или футер).

Решение — layout routes

React Router предлагает отличный способ: использовать layout routes. Это позволяет сохранять общие компоненты между страницами без их размонтирования.

Вот пример:


// Layout.jsx
import { Outlet } from "react-router-dom";

export default function Layout() {
return (
<>
<Header />
<main>
<Outlet />
</main>
<Footer />
</>
);
}



// App.jsx
import { Routes, Route } from "react-router-dom";
import Layout from "./Layout";
import Home from "./pages/Home";
import About from "./pages/About";

function App() {
return (
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="about" element={<About />} />
</Route>
</Routes>
);
}


Теперь Header и Footer не будут размонтироваться, и интерфейс останется стабильным при переходах.

👀 Плюс: можно добавить плавные анимации переходов с помощью framer-motion без артефактов.

Попробуйте — разница ощущается сразу.

✍️ @React_lib



tg-me.com/React_lib/675
Create:
Last Update:

🚀 Как избавиться от "тряски" компонентов при переключении страниц в React?

Сегодня хочу показать вам простой способ, как сделать ваш интерфейс более плавным при навигации между страницами.

Вы замечали, что при переходе между роутами компоненты "мигают" или резко перерисовываются? Особенно это бросается в глаза, когда вы используете React Router и на каждой новой странице заново монтируются одни и те же элементы (например, хедер или футер).

Решение — layout routes

React Router предлагает отличный способ: использовать layout routes. Это позволяет сохранять общие компоненты между страницами без их размонтирования.

Вот пример:


// Layout.jsx
import { Outlet } from "react-router-dom";

export default function Layout() {
return (
<>
<Header />
<main>
<Outlet />
</main>
<Footer />
</>
);
}



// App.jsx
import { Routes, Route } from "react-router-dom";
import Layout from "./Layout";
import Home from "./pages/Home";
import About from "./pages/About";

function App() {
return (
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="about" element={<About />} />
</Route>
</Routes>
);
}


Теперь Header и Footer не будут размонтироваться, и интерфейс останется стабильным при переходах.

👀 Плюс: можно добавить плавные анимации переходов с помощью framer-motion без артефактов.

Попробуйте — разница ощущается сразу.

✍️ @React_lib

BY React


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/React_lib/675

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Traders also expressed uncertainty about the situation with China Evergrande, as the indebted property company has not provided clarification about a key interest payment.In economic news, the Commerce Department reported an unexpected increase in U.S. new home sales in August.Crude oil prices climbed Friday and front-month WTI oil futures contracts saw gains for a fifth straight week amid tighter supplies. West Texas Intermediate Crude oil futures for November rose $0.68 or 0.9 percent at 73.98 a barrel. WTI Crude futures gained 2.8 percent for the week.

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

telegram from it


Telegram React
FROM USA