RRU 091: React Best Practices




React Round Up show

Summary: <p dir="ltr"><strong>In this week’s episode of React Round Up the panel works their way through a blog post outlining best practices for React. The first is “keeping components small and function-specific”. The panel discusses the pros of using this best practice and how it relates to the single responsibility principle. This best practice also helps with the next, “reusability is important”.</strong></p> <p dir="ltr"><strong>The panel considers this second best practice and points out some of its flaws. It recommends avoiding the creation of new components. The panel explains that by avoiding creating new components it saves time but can also cause problems as you adapt components to fit more projects. </strong></p> <p dir="ltr"><strong>The next best practice is “consolidate duplicate code”, the panel shares their philosophies on dry code and when to consolidate. The fourth best practice is comment only when necessary, Charles explains how he uses comments to help him keep track of things inside his code and the panel warns against using too many comments as it may clog up your code making it hard to read. </strong></p> <p dir="ltr"><strong>The fifth best practice is, “name the component after the function”. The panel explains how it is an art finding a name that is not too generic but is not overly specific; mastering the art of naming is something that will benefit everyone. </strong></p> <p dir="ltr"><strong>Naming relates to the sixth best practice as well. “Use capitals when naming components”. The panel explains the need for convention and advises developers not to go off-book as this will slow down others. </strong></p> <p dir="ltr"><strong>The last six best practices are all self-explanatory says the panel. “Separate stateful aspects from rendering” is nothing new. “Code should execute as expected and be testable”, the panel explains how this allows for trust between developers.  “All files relating to a single component should be in the same folder”, this makes everything easy to find when necessary. </strong></p> <p dir="ltr"><strong>“Use tools like Bit”, while the panel doesn’t use Bit, they share tool recommendations. They also comment on the progress being made it tooling and the future of automated tools. “Use snippet libraries”, the panel discusses favorite libraries and building their own libraries. The final best practice is “Follow linting rules”.</strong></p> <h3 dir="ltr"><strong>Panelists</strong></h3> <ul> <li dir="ltr"> <p dir="ltr"><strong>Charles Wood</strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong>Christopher Reyes</strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong>Thomas Aylott</strong></p> </li> </ul> <h3 dir="ltr"><strong>Sponsors</strong></h3> <ul> <li dir="ltr"> <p dir="ltr"><strong><a href="http://nxplaybook.com/">NxPlaybook.com</a> - Use code ‘NXDEVCHAT’ for 50% off the official<a href="https://nx.dev/React"> https://nx.dev/React</a> Advanced Workspaces course! </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="http://sentry.io/">Sentry</a>– use the code “devchat” for two months free on Sentry’s small plan</strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://www.cachefly.com/">CacheFly</a></strong></p> </li> </ul> <h3 dir="ltr"><strong>Links</strong></h3> <ul> <li dir="ltr"> <p dir="ltr"><strong><a href="https://teachablemachine.withgoogle.com/">https://teachablemachine.withgoogle.com/</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://blog.logrocket.com/practical-react-hooks-how-to-refactor-your-app-to-use-hooks-b1867e7b0a53/">Practical React Hooks: How to refactor your app to use Hooks</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://www.codeinwp.com/blog/react-best-practices/#disqus_thread">12 React Best Practices You Need to Follow in 2020</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://github.com/nadeesha/saul">https://github.com/nadeesha/saul</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://www.facebook.com/React-Round-Up">https://www.facebook.com/React-Round-Up</a></strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://twitter.com/reactroundup">https://twitter.com/reactroundup</a></strong></p> </li> </ul> <h3 dir="ltr"><strong>Picks</strong></h3> <p dir="ltr"><strong>Charles Wood:</strong></p> <ul> <li dir="ltr"> <p dir="ltr"><strong><a href="https://amzn.to/2D1WfnD">White Christmas</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://amzn.to/33ahvCx">Holiday Inn</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://amzn.to/2QBuBWI">The MaxCoders Guide To Finding Your Dream Developer Job</a> </strong></p> </li> </ul> <p dir="ltr"><strong>Christopher Reyes:</strong></p> <ul> <li dir="ltr"> <p dir="ltr"><strong><a href="https://github.com/microsoft/vscode-eslint">https://github.com/microsoft/vscode-eslint</a> </strong></p> </li> <li dir="ltr"> <p dir="ltr"><strong><a href="https://www.playingwithfire.co/">https://www.playingwithfire.co/</a> </strong></p> </li> </ul> <p dir="ltr"><strong>Thomas Aylott:</strong></p> <ul> <li><strong><a href="https://medium.com/@kentbeck_7670/test-commit-revert-870bbd756864">test &amp;&amp; commit || revert</a> </strong></li> </ul>