Can You Modify React Props?

preview_player
Показать описание
Did you know about this trick? #react #reactjs #reactjsdeveloper #programming #progammer #frontend #devtok #coding #code #codetok #cs
Рекомендации по теме
Комментарии
Автор

Actually you can directly change even state but this will not trigger the rendering. Data will change but you can't see

cenkakay
Автор

the first scenario will work as well. it will be bad idea because you change the props object, but it will work and it will not throw an error or a warning.

the reason why the 2nd scenario is ok it because "title" is a string (primitive). if it was an object it will still be a bad idea.

i know you know this... but somone how dont know this can mistakenly understand that the destructuringis some how magic that make the bugs go away

OmerMazig-zo
Автор

Dont know why youd really want to do this, creating the extra variable seems like less code to me:

const lowerCase = props.title.toLowercase

It uses one extra string's worth of memory, but makes way more sense, and wont break the prop for anyone else who tries to use it later, without catching your niche loophole around the rules of React

bobwilkinsonguitar
Автор

In this example, it would never occur to me to modify a prop to lower case its value with JS, I would just use css

youhabbo
Автор

Welll yea but ... i still wouldnt do it, as it will update this value on the parent which may not be what we want, but will not trigger state change, so it could lead to a pretty hard to debug scenario.

mladenorsolic
Автор

Hmm, never ran into is before cause I always destructure by default 😅😅😅 fun to know

UmehTobenna
Автор

I don't consider this a good idea a the destructured values from props are always looked upon as they must not have changed anywhere.

You debug with a mindset unless someone writes a line like this in the middle of 2 functions and you're scratching your head off why this happened?

Never do this? Js doesn't block anything with no type checks doesn't mean you start you doing things like this.

MASTERISHABH
Автор

People keep saying that Senior developers are more knowledgeable than mid level developers in code and that's not true. Senior is a title when you are given the accountability to handle architechtural decisions and design patterns. If senior was only to do with ability to code, then companies would only ever hire senior developers because why would they hire anyone else?

griffin
Автор

Wait, isn't this normal? Or have I been a hecker 😎 all this time without knowing it?

hikari
Автор

this is a very common practice i think

abhisheknavgan
Автор

This is not a good practice - there's a reason for the props being readonly...

brandonm
Автор

Bad practice and may result in unfirseen issues

darkmift
Автор

Please, people coming here, do not do this.

Monstermash
Автор

Why do you think so lowly of senior developers? This is basic javascript.

baldcoder_
Автор

you should really look for a job at tmz or something else man, stop with these bullshit claims seniors dont know..😅😅

thenotoriousrt
Автор

How is this surprising for seniors? Have they not learned JavaScript?!?!😮

PaulSebastianM