Telegram Group & Telegram Channel
Как использовать forwardRef с generic компонентами

Статья объясняет, как использовать forwardRef с обобщенными компонентами в TypeScript. Она рассматривает проблемы forwardRef с типизацией обобщенных компонентов и предлагает способ их решения. Этот метод позволяет сохранить типовую безопасность при передаче ссылок на компоненты.

Одно из ограничений forwardRef в том, что он отключает выведение типа для generic компонентов. Например:


const Table = <T,>(
props: {
data: T[];
renderRow: (row: T) => React.ReactNode;
},
ref: React.ForwardedRef<HTMLTableElement>
) => {
/** --snip-- */
};

const ForwardReffedTable = React.forwardRef(Table);

<Table
data={["a", "b"]}
renderRow={(row) => { // Тип выводится: row: string
return <tr>{row}</tr>;
}}
/>;

<ForwardReffedTable
data={["a", "b"]}
renderRow={(row) => { // Тип не выводится: row: unknown
return <tr>{row}</tr>;
}}
/>;


https://www.totaltypescript.com/forwardref-with-generic-components

✍️ @React_lib



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

Как использовать forwardRef с generic компонентами

Статья объясняет, как использовать forwardRef с обобщенными компонентами в TypeScript. Она рассматривает проблемы forwardRef с типизацией обобщенных компонентов и предлагает способ их решения. Этот метод позволяет сохранить типовую безопасность при передаче ссылок на компоненты.

Одно из ограничений forwardRef в том, что он отключает выведение типа для generic компонентов. Например:


const Table = <T,>(
props: {
data: T[];
renderRow: (row: T) => React.ReactNode;
},
ref: React.ForwardedRef<HTMLTableElement>
) => {
/** --snip-- */
};

const ForwardReffedTable = React.forwardRef(Table);

<Table
data={["a", "b"]}
renderRow={(row) => { // Тип выводится: row: string
return <tr>{row}</tr>;
}}
/>;

<ForwardReffedTable
data={["a", "b"]}
renderRow={(row) => { // Тип не выводится: row: unknown
return <tr>{row}</tr>;
}}
/>;


https://www.totaltypescript.com/forwardref-with-generic-components

✍️ @React_lib

BY React




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

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

Telegram Gives Up On Crypto Blockchain Project

Durov said on his Telegram channel today that the two and a half year blockchain and crypto project has been put to sleep. Ironically, after leaving Russia because the government wanted his encryption keys to his social media firm, Durov’s cryptocurrency idea lost steam because of a U.S. court. “The technology we created allowed for an open, free, decentralized exchange of value and ideas. TON had the potential to revolutionize how people store and transfer funds and information,” he wrote on his channel. “Unfortunately, a U.S. court stopped TON from happening.”

telegram from ye


Telegram React
FROM USA