From the course: React: Using TypeScript (2019)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

HOCs best practices

HOCs best practices

From the course: React: Using TypeScript (2019)

Start my 1-month free trial

HOCs best practices

- [Instructor] There are a lot more to discover with HOCs and this was a brief introduction with TypeScript implemented. What I'd recommend is to get familiar with HOCs without TypeScript first, and then as you get more comfortable with them add type inspection with TypeScript to make sure everything works. A few areas to remember when working with HOCs. Resist the urge to change the HOC or the prototype build as this could impact all your components that leverage it. If you need to pass props to a wrap component pass them through as the example we're seeing here and do not inject them in the wrap component. The props from a local state needs to be injected like we've done in our example. Do not use HOCs inside the render method as it could disrupt Reacts render algorithms and impact the performance of your application. And as far as TypeScript is concerned, always go back to the documentation when you're seeing weird type error messages as most of them can be solved through some…

Contents