DEV Community

Jalaj Bankar
Jalaj Bankar

Posted on

Git, React State, and a Few Things on the To-Learn List

Some days you cover a lot of ground — git tricks, React state patterns, and a handful of things you've bookmarked to dig into later. Today was one of those days.


git stash — "I'll Deal With This Later"
The best way to think about git stash is like putting your unfinished work in a drawer. You're not deleting it, you're not committing it — you're just saying "keep this safe, I'll come back to it." Super useful when you need to quickly switch branches without losing your current changes.
And if you've got multiple stashes piling up, git stash@{n} lets you point at a specific one — just like git stash pop but with more control over which entry you're grabbing.


git push --no-verify — Skipping the Gatekeeper
If your project uses Husky, it sets up pre-commit or pre-push hooks that run checks before your code goes anywhere — linting, tests, that kind of thing. Sometimes you just need to push quickly and skip all that. That's what git push --no-verify is for. Use it wisely though — those hooks exist for a reason.


onClick in React — Drop the Parentheses
When attaching a function to an event in React, just pass the function name directly:
onClick={handleClick} ✅
onClick={handleClick()} ❌

The second one calls the function immediately when the component renders — not when the user clicks. That's almost never what you want. No parentheses, just the name.


What useState Actually Gives You
If you ever console.log a useState variable, you'll see two things — the current value and a function ready to update it. That's exactly why we destructure it:
const [step, setStep] = useState(0);
The first item is your value, the second is your updater function. Once that mental model clicks, useState stops feeling weird.


One Variable, Many Places — The step Pattern
This is a really clean pattern worth internalising. You pick one state variable as your source of truth and let everything else reference it:
const [step, setStep] = useState(1);
function next() {
if (step < 3) setStep(step + 1);
}
function prev() {
if (step > 1) setStep(step - 1);
}

Your buttons, your displayed message, your active indicator — everything reads from step. Change step, everything updates. That's the beauty of state done right.


Updating an Object Inside useState
State doesn't have to be just a number or a string — it can hold an object too. And updating it is straightforward:
const [name, setName] = useState({ name: "Jalaj" });
setName({ name: "Shiva" });

One thing to keep in mind — when your object has multiple properties, you'll want to spread the old state first so you don't accidentally wipe the other fields: setName({ ...name, name: "Shiva" }). Small habit, saves big headaches.


Conditional Rendering
Rendering something only when a condition is true is one of those React superpowers you'll use in literally every project. Learned it today — more on this in a future entry once it's had time to sink in properly.


WSL, Git Default Editor, and CRLF/LF
Three things that came up and are sitting on the to-learn list:
WSL — Windows Subsystem for Linux. Lets you run a Linux environment right inside Windows. Big deal for developers who want Linux tools without dual booting.
Setting a default editor for Git — so when Git opens an editor for commit messages, it opens the one you actually want, not whatever it defaults to.
CRLF vs LF — Windows and Linux handle line endings differently, and Git sometimes gets opinionated about it. Worth understanding before it causes a confusing bug in a team project.

Top comments (0)