The single responsibility principle is a software development principle that states that a component should have only one reason to change. In other words, a component should have only one job or responsibility. This applies to components in React because it helps keep them simple, reusable, and maintainable.
Building a “static” version of your application means creating a version of your application that doesn’t have any interactivity or dynamic behavior. It’s a version of your application that just displays the data that you pass into it.
Once you have a static application, you need to add interactivity by adding stateful behavior to your components. This involves identifying which components need to be stateful, and determining what kind of state they need to manage.
The three questions you can ask to determine if something is state are:
You can identify where state needs to live by following these steps:
A “higher-order function” is a function that takes one or more functions as arguments, and/or returns a function as its result.
The greaterThan
function defined in the reading takes a number as an argument and returns a new function. Line 2 of the function is creating a new function that takes a single argument n
, and returns n > number
. This new function is then returned by the greaterThan
function, effectively creating a new function that can be used to test if a number is greater than the original number passed in as an argument.
map
and reduce
are higher-order functions that operate on arrays. map
takes a function as an argument and applies that function to each element of the array, returning a new array with the results. reduce
takes a function as an argument that combines each element of the array into a single value, and returns that value. Both map
and reduce
allow you to write more concise and expressive code by abstracting away common array operations into higher-order functions.