From the course: React: Design Patterns
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Component composition - React.js Tutorial
From the course: React: Design Patterns
Component composition
- [Instructor] Alright, so now that we've seen recursion and how it applies to React components, let's take a look at a slightly different concept called composition. Now, in a general way, what composition refers to, and let me just give you a little example here. I'm just going to create a file here called composition.jsx. And really composition refers to when you have multiple pieces of functionality that are fairly small and self-contained, but can also be combined to create something more complicated, right? Now, one could argue that that's really been something that we've been doing with most of the examples we've gone through so far in the course, but to give you an idea of what this looks like in a little bit more detail, let's start off here with just a few basic functions. Alright, so we'll say something like const and we'll create a function that maybe reverses a string, alright? So we'll say reverseString = and then this is just going to take a string and return that…