Stop Doing this as a React Developer

Stop Doing this as a React Developer

CoderOne

1 год назад

159,189 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Nishain de Silva
Nishain de Silva - 28.10.2023 16:30

I recently made another alternative to debouncing issue. It's technique to determine if user has copy and pasted value or actually typing value by calculating change of input text length. If user is typing user has explicitly need to click a button but if user has pasted value it will automatically trigger search function.

Ответить
Yenuan Osorno
Yenuan Osorno - 25.10.2023 12:14

Denounce is good, but for truly senior devs, you simply cache every idempotent iteration of whatever request makes sense to cache... if not almost all... So, just stop using lo-dash, have some balls and venture into cache re-validation, you will be really happy about all the errors you will introduce, get fired and find a better job as a consequence. Thank me later. (LOL)

Ответить
Deo Deo
Deo Deo - 24.10.2023 18:07

How about
!!showWinning &&
Will not show 0

Ответить
Lalit Aswal
Lalit Aswal - 14.10.2023 21:05

LOL why null after : just use the loser fragment

Ответить
Lota
Lota - 05.10.2023 16:49

I just watch a video that said && is better ...

Ответить
SH8YT
SH8YT - 09.09.2023 00:45

&& with array is 0 when length is 0

Ответить
Merlo
Merlo - 06.08.2023 11:05

wao, you vs**e looks like my neovim code editor, cool

Ответить
Hlib Shulzhenko
Hlib Shulzhenko - 30.07.2023 18:36

One blogger stated that using ternary operators is bad practice, while another recommended that conditional rendering should return false instead of null. It's great that I can merge both recommendations.
However, it's unfortunate that the React documentation doesn't provide a comments answer on such small but useful tips.

Ответить
Tushar Jain
Tushar Jain - 24.07.2023 18:58

I use !! to avoid 0 😂

Ответить
sky lan
sky lan - 06.07.2023 19:41

It seems that use useRef for debounceValue instead of useState in useDebounce is much better, because it reduces the times of re-render

Ответить
JustIn
JustIn - 26.06.2023 11:30

why not just use the useeffect and grab the data once on mount

Ответить
Thiago Leobons
Thiago Leobons - 08.06.2023 03:22

That's why everyone uses typescript. Boolean && is just fine, keep using it

Ответить
Yash Chauhan
Yash Chauhan - 03.06.2023 08:03

!! <---- this works most fo the time

Ответить
Flo D
Flo D - 08.04.2023 19:43

just use typescript

Ответить
Shyam Mahanta
Shyam Mahanta - 06.03.2023 17:36

watched a nonsense video which doesnt make sense.

Ответить
Allan Ferreira
Allan Ferreira - 06.03.2023 14:56

next time, read the documentation instead of teaching something that you don't understand. there is nothing wrong about using "&&" operator to render something. just the very old versions of React API needed to return null

Ответить
LexVale
LexVale - 19.02.2023 00:41

imagine not using typescript

Ответить
Alexey Shaykov
Alexey Shaykov - 03.02.2023 13:27

Thanks a lot. I thinking about conditional rendering: IMHO the best is create function, like renderSomethink, and inside this function return some part of jsx in conditional case

const renderSomethink = () => {
if (flag) {
return (<div>aaa</div>)
}

return <div>bbb</div>
};

return (
{renderSomethink()}
)

ternary operators (?:) in jsx template it is terrible practice

Ответить
Recep Çiftçi
Recep Çiftçi - 25.01.2023 20:55

Very misleading thumbnail. Disappointed.
Bullshit reasoning for conditional rendering that has a chance of 1/10^100000000

Ответить
Philipp R
Philipp R - 04.01.2023 14:20

If you actually have an if+else condition in rendering, going for ternary operators (?:) is also my preferred way, but if your else is just "render nothing", so "condition ? <>something</> : null", going for "condition && <>something</>" is totally fine and also my preferred way.
If your condition can be a falsy value that gets rendered by react (e.g. 0), just put a !! in front of it so parse it boolean. It's not a bad thing to do so.

If you are scared of bugs changing your condition's type, this is not the right spot to fix it. You should generally always parse incoming data from a third party (an api, user input, etc.). You could use libs like Zod for that.
But taking that as a reason to not use && or || operators is a weird way to think imo

Ответить