Warning: mkdir(): No space left on device in /var/www/tgoop/post.php on line 37

Warning: file_put_contents(aCache/aDaily/post/frontend_1/--): Failed to open stream: No such file or directory in /var/www/tgoop/post.php on line 50
Frontend разработчик@frontend_1 P.3975
FRONTEND_1 Telegram 3975
🔥 Юзаешь React + TypeScript? Тогда вот тебе трюк на миллион — типизация children правильно!

Часто можно увидеть вот так:


type Props = {
children: React.ReactNode;
}


Но это слишком широкий тип. Он допускает что угодно: строки, числа, фрагменты, null…

📌 Лучше — использовать ReactElement:


import { ReactElement } from 'react';

type Props = {
children: ReactElement;
}


👉 Это значит: ожидаем ровно один React-элемент, и никаких строк/чисел/массивов.

Если нужно несколько элементов — используем:


type Props = {
children: ReactElement | ReactElement[];
}


🎯 Это даёт жёсткую и предсказуемую типизацию, особенно полезно для обёрток и layout-компонентов.

⚠️ А если хочешь прям универсальность — тогда ReactNode ок. Но осознанно.


Пиши типы как профи 💪

👉 @frontend_1
👍91



tgoop.com/frontend_1/3975
Create:
Last Update:

🔥 Юзаешь React + TypeScript? Тогда вот тебе трюк на миллион — типизация children правильно!

Часто можно увидеть вот так:


type Props = {
children: React.ReactNode;
}


Но это слишком широкий тип. Он допускает что угодно: строки, числа, фрагменты, null…

📌 Лучше — использовать ReactElement:


import { ReactElement } from 'react';

type Props = {
children: ReactElement;
}


👉 Это значит: ожидаем ровно один React-элемент, и никаких строк/чисел/массивов.

Если нужно несколько элементов — используем:


type Props = {
children: ReactElement | ReactElement[];
}


🎯 Это даёт жёсткую и предсказуемую типизацию, особенно полезно для обёрток и layout-компонентов.

⚠️ А если хочешь прям универсальность — тогда ReactNode ок. Но осознанно.


Пиши типы как профи 💪

👉 @frontend_1

BY Frontend разработчик




Share with your friend now:
tgoop.com/frontend_1/3975

View MORE
Open in Telegram


Telegram News

Date: |

‘Ban’ on Telegram There have been several contributions to the group with members posting voice notes of screaming, yelling, groaning, and wailing in different rhythms and pitches. Calling out the “degenerate” community or the crypto obsessives that engage in high-risk trading, Co-founder of NFT renting protocol Rentable World emiliano.eth shared this group on his Twitter. He wrote: “hey degen, are you stressed? Just let it out all out. Voice only tg channel for screaming”. Invite up to 200 users from your contacts to join your channel Earlier, crypto enthusiasts had created a self-described “meme app” dubbed “gm” app wherein users would greet each other with “gm” or “good morning” messages. However, in September 2021, the gm app was down after a hacker reportedly gained access to the user data. A few years ago, you had to use a special bot to run a poll on Telegram. Now you can easily do that yourself in two clicks. Hit the Menu icon and select “Create Poll.” Write your question and add up to 10 options. Running polls is a powerful strategy for getting feedback from your audience. If you’re considering the possibility of modifying your channel in any way, be sure to ask your subscribers’ opinions first.
from us


Telegram Frontend разработчик
FROM American