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


React Telegram | DID YOU KNOW?

Date: |

How Does Bitcoin Mining Work?

Bitcoin mining is the process of adding new transactions to the Bitcoin blockchain. It’s a tough job. People who choose to mine Bitcoin use a process called proof of work, deploying computers in a race to solve mathematical puzzles that verify transactions.To entice miners to keep racing to solve the puzzles and support the overall system, the Bitcoin code rewards miners with new Bitcoins. “This is how new coins are created” and new transactions are added to the blockchain, says Okoro.

Should You Buy Bitcoin?

In general, many financial experts support their clients’ desire to buy cryptocurrency, but they don’t recommend it unless clients express interest. “The biggest concern for us is if someone wants to invest in crypto and the investment they choose doesn’t do well, and then all of a sudden they can’t send their kids to college,” says Ian Harvey, a certified financial planner (CFP) in New York City. “Then it wasn’t worth the risk.” The speculative nature of cryptocurrency leads some planners to recommend it for clients’ “side” investments. “Some call it a Vegas account,” says Scott Hammel, a CFP in Dallas. “Let’s keep this away from our real long-term perspective, make sure it doesn’t become too large a portion of your portfolio.” In a very real sense, Bitcoin is like a single stock, and advisors wouldn’t recommend putting a sizable part of your portfolio into any one company. At most, planners suggest putting no more than 1% to 10% into Bitcoin if you’re passionate about it. “If it was one stock, you would never allocate any significant portion of your portfolio to it,” Hammel says.

React from us


Telegram React
FROM USA