Principles of React
Before we start learning how to set up a full-stack React project, let’s revisit the three fundamental principles of React. These principles allow us to easily write scalable web applications:
- Declarative: Instead of telling React how to do things, we tell it what we want it to do. As a result, we can easily design our applications and React will efficiently update and render just the right components when the data changes. For example, the following code, which duplicates strings in an array is imperative, which is the opposite of declarative:
const input = ['a', 'b', 'c'] let result = [] for (let i = 0; i < input.length; i++) { result.push(input[i] + input[i]) } console.log(result) // prints: [ 'aa', 'bb', 'cc' ]
As we can see, in imperative code, we need to tell JavaScript exactly what to do, step by step. However, with declarative code, we can simply tell the computer what...