React Best Practices You Need To Follow In 2019

Juan Manuel Sobral
3 min readOct 7, 2019

Ever heard of React or ReactJS… No?

Well, as an interface or framework developer, you are missing out on a lot. React has revolutionized the way in which user interfaces are built. It is one of those popular smart-guy tools that have surpassed jQuery, and you can Google it to see for yourself, but we are not here to compare tools; So you can save yourself the trouble and just focus on React which helps you create amazing interfaces and front-end apps.

Before we move on to the best practices, here is what else you need to know about React:

It was built by Facebook, so you know that it has amazing potential and helps you build quality interfaces. It’s optimized for performance using virtual DOM which helps quickly render elements that need updating. It uses JavaScript to create apps. It only focuses on the top-most layer of apps, which makes it difficult to keep the code base organized as a React project grows.

React Best Practices in 2019

Without keeping you in the dark any further, here are the best React practices you need to follow in 2019 to make the most of your skills:

  • Use the create-react application generator to bootstrap the ReactJS app.
  • Use more robust managers, like Redux to manage application state.
  • Use TypeScript when writing code for apps
  • Do not have large classes, components or methods that include Reducers.
  • Split the Reducer code into small methods to avoid JSON when using ReduxJS.
  • When coding, do not repeat yourself… “Keep it DRY”, but having duplicate codes is not always bad!
  • Limit to five or six props that you pass into the component… Avoid passing too many arguments or attributes.
  • Ever heard of Redux-Thunk… It’s the event synchronizer that helps interact with a back-end API.
  • Keep the jslint configuration file.
  • Try using ReactJS propTypes and ReactJS defaultProps.
  • Always remember to use yarn or NPM, either dependency manager with a lock file.
  • Use linter… it breaks up the longer lines.
  • Write a test first whenever you find a bug.
  • Test the code that is commonly accessed, one that is complex and also prone to bugs.
  • Use ES6 destructuring for props.
  • Write tests that give more test coverage for the code and ensure proper functioning.
  • Use conditional rendering.
  • Use React Hooks — a new way to create state-full components.
  • Use partial components like ‘</>’ and ‘<>’.
  • To collect and render component collections, use ‘map ()’.
  • To test your ReactJS code, use JEST.
  • If you want to control your inputs like ‘onChange = {this.handleInputChange ()}’, use ‘onChange’!
  • You should name the event handlers with handle prefixes like ‘handleUpdate ()’ or ‘handleClick ()’.

So, if you are a fan of clean coding and you can find your way around React¸ you are well on your way to becoming a smart and popular developer. If you are still trying to get the hang of it, it is never too late… Start with this article!

--

--