Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "setstate"
-
Got asked to fix a bug at work. The code (react) looked like this:
file = form.file;
this.setState({file});
this.methodThatNeedsFile();
So i explained that the changes from setState are not adopted immediately etc. Then i take another look at the code and feel the pain in my head. You could shorten the code to:
this.methodThatNeedsFile(form.file);
Is there some subconscious need in the brain to make use of frameworks even though it makes no goddamn sense and "normal" programming is sufficient? -
Please fucking tell me there's a better cleaner way to write this render() function?
The use of so many "in-line" code evaluations, arrow functions, (), {}, ...
Just spent like probably 30 minutes just trying to figure out what closes what...
And the author is inconsistent?
Sometimes he uses map( location => { return ... })
other times he uses setState((prevState) => ({ key: this.state.keyValue}))
And there's no note as to why... are they interchangeable, used in specific cases, does it matter????!!!!!!
Or is he just trying to demonstrate 1000 different ways you can say the same thing in JS?
!@#!#@!$#%#$!@#!@#!#$$%30 -
Why React is soo complicated? Seriously why do we always need to use some stupid shit like this
const [state, setState] = useState();
what the fuck is this? Who designed it that way, why it should always look like shit for no reason? Why its API feels like spaghetti? When i am comparing other front-end frameworks they feel like heaven in their structure.
AND WHAT IS WRONG WITH ME HAVING A QUOTE ON A PARAGRAPH ELEMENT, WHY DO I HAVE TO USE FUCKING HTMLENTITES FROM 2000?
FUCK'ERE35 -
So, today I revisited my 5 months old code and was like "What? Did I really wrote this horrible code?" 😐️ 🙂️ 😃️🔫️
```js
setState((initVal) => {
initVal.food = 'burger';
return initVal;
});
```
The function above change its argument's value, which is terrible thing to do, since it will also change the original value passed to the function. A variable's value for example. Making it an impure function.6 -
Thank you React...for making easy things easier, hard things easier, and medium level things so flipping overkill that somewhere in the world a developer loses their wings every time you type "setState".
-
Dealing with React's setState and looking through all the possible lifecycle methods was so frustrating today.
It should have been a simple thing to disable a button, via the disabled prop, on click. I thought it would be enough to say
this.setState({ disableButton: true });
someSynchronousCode();
this.setState({ disableButton: false });
in the handler ... but it wasn't. The button would still be active for about a second after clicking. I tried several things like converting the synchronous code to a promise, trying componentDidUpdate with a comparison. It all failed. Interestingly enough removing the 2nd setState immediately disabled the button, though making it permanent.🙄
I've found a solution which seemed a bit hacky, changing the state back depending on another variable in the render method.
It seems so wrong, but it was the only solution I found after several hours.3 -
Anyone using Redux Thunk with a router? Can I cancel a promise on location change like in Redux Saga? Occasional setState warning appeared to me and it's annoying
-
We learn everyday. So for the early hours of today, I've learnt how to use redux(reducers and action) to manage my state and hell, my components are looking alot organized now than calling set and setState everywhere.
Learnt that fetchById was replaced by fetchByPk for fetching single item when using sequelize in Node.js
Learnt you can display images in your django admin panel. Haven't thought about it until today.
Well end of rant.
#JobHunting #LifeOfASoftwareDeveloper #JuniorDev -
Is using getx's `ever` function a code smell? I'm using getx as a library rather than a framework ie state management instead of wrapping the app in it and using their widgets
My background from writing reactive code in vuex is that whenever a watched variable in the overarching store is updated, it automatically calls its listeners and re-renders the view. However, my flutter widgets remain stagnant except I explicitly mount the ever worker and call setState on a local field basically duplicating the store variable/field. It feels hacky to me tbh and leads to errors about calling setState on non-mounted screens, which I'm circumventing by checking if mounted (another hack)
It feels contrived like Band-aid over an actual problem. Is there a more natural way to propagate changes? I'm neither using getBuilder nor obx cuz a significant portion of my code entails computing stuff rather than just outputting data off an api. I want ui decisions to reside on my statefulWidget rather than migrating them to getx controller
Is this really how the project functions, should it be used a specific way, or am I missing something?6