What is Composition ?
자바스크립트에서 함수를 사용할지를 결정하는것은 자연스러운일입니다. 리액트에서도 같은 직관적 판단(intuition)을 리액트컴포넌트를 만들때 발휘할 수 있습니다. 하지만 arguments를 받아 value를 반환했던 일반적 함수와 다르게, 이번에는 ui를 반환합니다.
compose함수의 예 (underscore.js)
compose_.compose(*functions)
Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).
var greet = function(name){ return "hi: " + name; };
var exclaim = function(statement){ return statement.toUpperCase() + "!"; };
var welcome = _.compose(greet, exclaim);
welcome('moe');
//=> 'hi: MOE!'
const add = x => y => x + y;
const multiply = x => y => x * y;
const add2Multiply3 = compose(multiply(3), add(2));
//add2Multiply3(3)
//const value = (x + 2) * 3
const tag = t => contents => `<${t}>${contents}</${t}>`
tag('b')('this is bold!')
//> <b>this is bold!</b>
https://hackernoon.com/javascript-functional-composition-for-every-day-use-22421ef65a10
명령적 코드 , 선언적코드
명령적코드에서는 과정을 명시하기때문에 버그가 발생할 확률이 높은데 반해 선언적코드는 그런부분이 없다. 리액트에서는 선언적 코드를 사용합니다.
https://tylermcginnis.com/imperative-vs-declarative-programming/