Notice: file_put_contents(): Write of 16980 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50
Frontender Libs - обзор библиотек JS / CSS@sWebDev P.3608
SWEBDEV Telegram 3608
Управление асинхронным рендерингом

Метод flushSync() позволяет немедленно обновить состояние и выполнить ререндер, обходя пакетную обработку обновлений. Это полезно, когда требуется мгновенно обновить интерфейс перед выполнением других операций, например, чтением размеров DOM.

Например, кнопка изменяет текст элемента, и нам нужно получить его новую ширину до следующего рендера:
import { useState } from "react";
import { flushSync } from "react-dom";

function Example() {
const [text, setText] = useState("Нажми меня");
const spanRef = useRef(null);

function handleClick() {
flushSync(() => {
setText("Текст изменился!");
});

console.log("Ширина:", spanRef.current.offsetWidth);
}

return (
<div>
<button onClick={handleClick}>Изменить</button>
<span ref={spanRef}>{text}</span>
</div>
);
}


flushSync() гарантирует, что offsetWidth обновится после изменения текста, а не после следующего рендера.

👉 @sWebDev
👍5



tgoop.com/sWebDev/3608
Create:
Last Update:

Управление асинхронным рендерингом

Метод flushSync() позволяет немедленно обновить состояние и выполнить ререндер, обходя пакетную обработку обновлений. Это полезно, когда требуется мгновенно обновить интерфейс перед выполнением других операций, например, чтением размеров DOM.

Например, кнопка изменяет текст элемента, и нам нужно получить его новую ширину до следующего рендера:

import { useState } from "react";
import { flushSync } from "react-dom";

function Example() {
const [text, setText] = useState("Нажми меня");
const spanRef = useRef(null);

function handleClick() {
flushSync(() => {
setText("Текст изменился!");
});

console.log("Ширина:", spanRef.current.offsetWidth);
}

return (
<div>
<button onClick={handleClick}>Изменить</button>
<span ref={spanRef}>{text}</span>
</div>
);
}


flushSync() гарантирует, что offsetWidth обновится после изменения текста, а не после следующего рендера.

👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tgoop.com/sWebDev/3608

View MORE
Open in Telegram


Telegram News

Date: |

The best encrypted messaging apps On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of “doxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. When choosing the right name for your Telegram channel, use the language of your target audience. The name must sum up the essence of your channel in 1-3 words. If you’re planning to expand your Telegram audience, it makes sense to incorporate keywords into your name. How to Create a Private or Public Channel on Telegram?
from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM American