Telegram Group & Telegram Channel
useContextSelector: Ускорение работы React-приложений

Случалось ли вам иметь контекст, который был настолько велик, что негативно влиял на производительность вашего React-приложения? Это происходит потому, что одно изменение значения контекста приводит к рендерингу всех компонентов, зависящих от этого контекста.

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


import { createContext, useState } from 'react';

const defaultTheme = { color: '#aabbcc', fontFamily: 'Arial', fontSize: 16 };

export const ThemeContext = createContext(defaultTheme);

export const ThemeContextProvider = ({ value = defaultTheme, children }) => {
const [theme, setTheme] = useState(value);
return (
<ThemeContext.Provider value={{ theme, setTheme }}>
{children}
</ThemeContext.Provider>
);
};

export const useTheme = () => {
const { theme } = useContext(ThemeContext);
return theme;
}


https://marmelab.com/blog/2024/10/16/usecontextselector-a-faster-usecontext-for-react.html

✍️ @React_lib



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

useContextSelector: Ускорение работы React-приложений

Случалось ли вам иметь контекст, который был настолько велик, что негативно влиял на производительность вашего React-приложения? Это происходит потому, что одно изменение значения контекста приводит к рендерингу всех компонентов, зависящих от этого контекста.

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


import { createContext, useState } from 'react';

const defaultTheme = { color: '#aabbcc', fontFamily: 'Arial', fontSize: 16 };

export const ThemeContext = createContext(defaultTheme);

export const ThemeContextProvider = ({ value = defaultTheme, children }) => {
const [theme, setTheme] = useState(value);
return (
<ThemeContext.Provider value={{ theme, setTheme }}>
{children}
</ThemeContext.Provider>
);
};

export const useTheme = () => {
const { theme } = useContext(ThemeContext);
return theme;
}


https://marmelab.com/blog/2024/10/16/usecontextselector-a-faster-usecontext-for-react.html

✍️ @React_lib

BY React




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

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

What is Telegram Possible Future Strategies?

Cryptoassets enthusiasts use this application for their trade activities, and they may make donations for this cause.If somehow Telegram do run out of money to sustain themselves they will probably introduce some features that will not hinder the rudimentary principle of Telegram but provide users with enhanced and enriched experience. This could be similar to features where characters can be customized in a game which directly do not affect the in-game strategies but add to the experience.

To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.

telegram from cn


Telegram React
FROM USA