Passing properties
As you have already seen in the example application, there are multiple ways to pass data around in an application. Some best practices have been established that you should definitely stick to; otherwise, your application can get very hard to debug and maintain. We list these here:
- Never modify a component state in an unpredictable way from outside the component: I know—I repeat myself; we had this in the previous section, but this is very important. Modifying your state in an unpredictable way from outside the component can lead to bad errors, especially when you are working on a large project with a team of developers. But let’s have a look in detail.
Unpredictable in this scenario means that you pass the setter function of your state directly to other components.
Why is this so bad? Because other components and maybe other developers can decide what to put in the state of your component. It is very likely that sooner or later...