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: |

Telegram announces Anonymous Admins

The cloud-based messaging platform is also adding Anonymous Group Admins feature. As per Telegram, this feature is being introduced for safer protests. As per the Telegram blog post, users can “Toggle Remain Anonymous in Admin rights to enable Batman mode. The anonymized admin will be hidden in the list of group members, and their messages in the chat will be signed with the group name, similar to channel posts.”

Telegram today rolling out an update which brings with it several new features.The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations.

telegram from us


Telegram React
FROM USA