Комментарии:
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.
Ответить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)
ОтветитьHow about
!!showWinning &&
Will not show 0
LOL why null after : just use the loser fragment
ОтветитьI just watch a video that said && is better ...
Ответить&& with array is 0 when length is 0
Ответитьwao, you vs**e looks like my neovim code editor, cool
Ответить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.
I use !! to avoid 0 😂
ОтветитьIt seems that use useRef for debounceValue instead of useState in useDebounce is much better, because it reduces the times of re-render
Ответитьwhy not just use the useeffect and grab the data once on mount
ОтветитьThat's why everyone uses typescript. Boolean && is just fine, keep using it
Ответить!! <---- this works most fo the time
Ответитьjust use typescript
Ответитьwatched a nonsense video which doesnt make sense.
Ответить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
Ответитьimagine not using typescript
Ответить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
Very misleading thumbnail. Disappointed.
Bullshit reasoning for conditional rendering that has a chance of 1/10^100000000
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