Monthly Archives: August 2020

Displaying a list of users from an API with typescript, hooks, and redux-toolkit

I use redux a lot, but i had never really tried redux-toolkit before. It took me a while to overcome the impression “oh look, data flying everywhere” and to recognise the familiar redux patterns — especially in the wildly terse createSlice.

What can I say about it? It’s wonderfully succinct compared to the boilerplate-dense standard redux experience. It’s darn clever to use a Proxy to encapsulate the object in draft state.

However, I am not convinced. Do I really need an opinionated library in case me or someone else in my team decides to slap an api call in a reducer? That would never pass a code review, anyway. And the library is so unconvinced that devs understand immutability that it makes it invisible, encouraging — heck, forcing — us to do something as horrid-looking as

state.users.push(...payload);

because immutability will be taken care of away by it, out of sight. Well, hmm, no, I suspect it’s not for me; although it may have its place in a team of redux-haters. Who am I to judge? 🙂 I won’t probably use it tho.

https://gist.github.com/barbaracassani/4b07c3b1f0ec49ff9b661eece78a1769

EDIT: a few months later and… once you get used to its admittedly quirky API (notably, the distinction between reducers and extraReducers feels awkward), it’s actually pretty neat to use. It drastically reduces the amount of boilerplate and duplication that affects normal Redux, and having Immer to handle immutability becomes really comfortable really quickly. So, I have been using it, with satisfaction.

The shoemaker always wears broken shoes

Six years since I last updated my website. In any sense: the temporary template remains there, I didn’t write any new posts. Well, I have been busy. Many many things have been going on in kitsch-en.net towers. Somewhat, this little job always fell at the bottom of my priorities’ list.

So today I thought it may be the day that I actually do something about it. Except that… well, I fell into a rabbit hole of meditations about React functional vs class components, and hooks and race conditions and…

You can imagine where this is going. The temporary website is still here. I really didn’t do much, but I put together this gist about using hooks to manage state in a tiny dynamic image gallery. It’s only a demonstration — nothing prod-worthy. But I hope someone finds it useful.

https://gist.github.com/barbaracassani/b47b4827365646b27d220b2d96abd08e

One day I will update this website… soon! 🙂