callIfFunction, applyIfFunction
Closed this issue · 2 comments
tommmyy commented
const ref = { current: null };
const getRef = always(ref);
const createRef = (current) => ({ current });
applyIfFunction(ref, []); // { current: null }
applyIfFunction(getRef, []); // { current: null }
applyIfFunction(createRef, [document.body]); // {"current": [object HTMLBodyElement]}
callIfFunction(ref) // { current: null }
callIfFunction(getRef) // { current: null }
callIfFunction(createRef, document.body) // {"current": [object HTMLBodyElement]}
I ofter use the function in React components.
Sometimes a property is either function (then you need to call it) or just static value.
wafflepie commented
Love the idea!