Trump humiliates reporters in explosive outburst as he heads on landmark China trip
Man United Under-18 boss Darren Fletcher reveals how he is preparing first-team stars of the future - and hits out at decision not to hold FA Youth Cup final at Old Trafford
Hailey Bieber puts on cheeky display as she appears to go NUDE under blue coat for major fashion campaign
Paramedics helping mother stuck headfirst in sea defence rocks as tide came in failed to follow guidance assuming she could not be saved, expert tells inquest
Prince Harry loses key player at the top of Invictus Games charity - just months after he was forced to step away from another
Are YOU headed for an 'unpreventable divorce'? TRACEY COX lays out the scenarios that no amount of therapy or forgiveness can overcome - and the 5 thorny issues you can fix
Albanian people smugglers mock UK's soft borders on TikTok as they advertise £2,000-a-head cross Channel trips by sharing clip of Jacob Rees Mogg highlighting small boat crisis
Rush hour woes as obstruction causes severe delays on key route
The travellers plotting SECOND illegal land grab in Essex hamlet: Family who bulldozed over countryside in Surrey buy field for £150K
My hedge grows into my neighbour's garden: Can he force me to cut it?
Why Are Some People Mosquito Magnets?
Read more of this story at Slashdot.
Harlow Tory leader vows to fight 'crazy' plans to dismantle council
Billionaire Aston Villa and Milwaukee Bucks owner Wesley Edens allegedly extorted by Chinese divorcee for $1bn after sordid love affair, prosecutor claims
Sydney Sweeney, 28, is gyrated on by Scooter Braun, 44, in PDA-packed clip from couple's Australian getaway
CodeSOD: Over and Under Reaction
Today's anonymous submitter sends us two blocks. The first is a perfectly normal line of React code:
const [width, setWidth] = useState(false)This creates a width variable, defaulting it to false, and a setWidth function, which lets React detect when you change the variable, and trigger a re-render. Importantly, this mutation only happens on the next render, which means if you call setWidth and then check width, you won't see your change happen.
As I said, this is perfectly normal React code. Well, almost. First, I have to ask: why on Earth is width being set to a boolean value? "How wide are you?" "Yes." It's possible that there's a good reason for this, though I suspect that it's unlikely.
The second issue, however, is that the linter complained that the setter was never actually used. That was odd, because if our submitter grepped the codebase, there were two calls to setWidth. Let's see what that looked like:
const show = (show) => { setWidth(show) setWidth(!show) }We create a function show, where we expect a boolean value, and then we setWidth with that value, and then with the negation of that value. So show(true) will set width to be false. To make matters more confusing, we set width both ways, and I assume this is someone trying to get around React's state management. React won't trigger a re-render if you set the state to a value it already has. So I suspect they're twiddling to try and force it to re-render, and I also suspect that this might not work? Even if it does, this isn't how you should be using React. As I said, I'm no React expert, but as the saying goes: "I don't have to be a helicopter pilot to know that when I see a helicopter hanging upside down from a tree someone messed up."
Our submitter writes:
Got hired to cleanup a mission critical website for a company that had just learned that offshore teams might not be worth the cost saving measures.
"Pay me now or pay me later."