18 hours agoReact project structure for scale: decomposition, layers and hierarchyHow to structure React apps “the right way” seems to be the hot topic recently for as long as React existed. React’s official opinion on it is that it “doesn’t have opinions”. This is great, it gives us total freedom to do whatever we want. And also it’s bad. …React20 min read
May 10React key attribute: best practices for performant listsReact “key” attribute is probably one of the most “autopilot” used features in React 😅 Who among us honestly can say that they use it because of “…some valid reasons”, rather than “because eslint rule complained at me”. And I suspect most people when faced with the question “why does…React10 min read
Published in Level Up Coding·Apr 12React components composition: how to get it rightOne of the most interesting and challenging things in React is not mastering some advanced techniques for state management or how to use Context properly. More complicated to get right is how and when we should separate our code into independent components and how to compose them properly. I often…React15 min read
Mar 23Implementing advanced usePrevious hook with React useRefAfter Context, ref is probably the most mysterious part of React. We almost got used to the ref attribute on our components, but not everyone is aware, that its usage is not limited to passing it back and forth between components and attaching it to the DOM nodes. We actually…React9 min read
Published in JavaScript in Plain English·Mar 1Have React Hooks Made Higher-Order Components Obsolete?Higher-Order Components in the React Hooks Era — Is it true that React hooks have made higher-order components obsolete? And the only use case for those is to be a remnant of the past in some existential legacy corners of our apps? And what is a higher-order component anyway? Why did we need them in the first place? …React13 min read
Feb 17React component as prop: the right way™️As always in React, there is one million way to do exactly the same thing. If, for example, I need to pass a component as a prop to another component, how should I do this? If I search the popular open-source libraries for an answer, I will find that: I…React12 min read
Published in Level Up Coding·Feb 10How to Write Performant React Apps with ContextIt’s impossible to have a conversation on how to write performant React code without having an article or two on Context. And it’s such a controversial topic! There are so many prejudices and rumours surrounding it. Context is evil! React re-renders everything for no reason when you use Context! Sometimes…React14 min read
Published in JavaScript in Plain English·Jan 25Why Custom React Hooks Could Destroy Your App’s PerformanceExploring why React custom hooks could be bad for react performance and what to do about it. — Scary title, isn’t it? The sad part is that it’s true: for performance-sensitive apps custom React hooks can very easily turn into the biggest performance killer, if not written and used very carefully. I’m not going to explain how to build and use hooks here, if you never built a…React11 min read
Published in Level Up Coding·Jan 12How to write performant React code: rules, patterns, do’s and don’tsPerformance and React! Such a fun topic with so many controversial opinions and so many best practices flipping to be the opposite in just 6 months. Is it even possible to say anything definitive here or to make any generalized recommendations? Usually, performance experts are the proponents of “premature optimisation…React18 min read
Dec 30, 2021Advanced typescript for React developers — discriminated unionsHello, my fellow React developers who are in the process of learning advanced typescript patterns! Did you know that typescript has something that is called “discriminated unions”? That name triggers all sorts of saviour reflexes against discrimination in me, but it actually is a pretty cool and useful feature that…React10 min read