React
2025
This post will be different from other texts I’ve put on this blog so far. Instead of digging deep into a singe topic, I’ll mention some issues that stumped me recently and suggest solutions. These issues might be quite niche, but I hope it will help at least one person get unstuck. Well, it might be me in the future. I’m 40 now - it’s about time I started writing things down ;)
2024
I’ve been relying on Material UI Box components quite a lot, because doing so allows use of theme-aware sx property and common attributes such as display or gap. It makes code more consistent with other uses of MUI components.
The Redux Thunks offer a good way of separating logic from UI components. Within a thunk, you can: access the entire state, dispatch actions and thunks, generate side effects (contrary to reducers)… Redux Toolkit contains the redux-thunk middleware and adds it during standard store configuration, nice.
A couple of months ago, I’ve migrated my vim.morzel.net hobby project from Create React App to Vite and noted down a few things that required attention. Recently, while adding dark mode to the same project, I’ve spotted another difference between CRA and Vite: class names for CSS modules were build differently.
2023
I’ve recently made the decision to migrate my vim.morzel.net pet-project from Create React App to Vite. To be honest, I was quite content with how CRA (with a bit of React App Rewired) functioned, and updating might not have been necessary. However, I wanted to use this migration as practice before possibly employing Vite on something more serious (where the speed and active development of Vite might prove a blessing).
2021
Last post was about suppressing chosen console warnings while executing tests. This one is also about making tests output less noisy…
In preparation for async rendering, React team decided to discourage component authors from relaying on these lifecycle methods: componentWillMount, componentWillReceiveProps and componentWillUpdate (details).
2020
In JavaScript, an ag-Grid column is bound to a row property by assigning a string to field config. This is quite fragile: a typo or change in row model will cause and empty column in the grid. Fortunately, a much safer binding is possible thanks to TypeScript’s keyof operator. Check grid component example and demo page.
Vanilla JS cell renderers are faster than framework renderers (just like the docs suggest) but renderers created with React class components are quite decent. Unfortunately, cell renderers build with function components are noticeably worse. The grid team is aware of the issue and might fix it soon (I’ve done my test on ag-Grid 23.1.0 released just 2 days ago)… See live demo that compares different ways to render cell content and check the source code on GitHub.
You can use measureText method to calculate widths of text and then use setColumnWidth to adjust columns. This the demo and this is the repo. It’s quite likely that you don’t need this technique (suppressColumnVirtualisation might be enough), but read on if your grid has huge amount of columns and users need high data density…
Utilize useState or useRef hooks and gridReady event to maintain access to Grid API and Column API. Check here for code samples.