Now I have a general understanding about functional prograamming, I am going to talk about why understanding functional programming is import when working on a React project.
React
component must have an output via render()
React components are pure components, but more importantly, the render
function inside a react componenet must be a pure function which always returns the same output if the input, which is state
in this case, is the same.
In functional programming, functions are not supposed to change its input values. Similarly, a React component cannot change its props
When a higher order function takes an argument and returns a function, a higher order component takes an arguments and returns a component. Simple examples are withRouter
in React-router, which is used in order to transfer a user to another webpage, or connect
in Redux, which connects a React component to a Redux store.