Last active
April 9, 2022 08:23
-
-
Save raaar/d65591c869e32ea639cbf74cc2a2ccfc to your computer and use it in GitHub Desktop.
The magic behind π
styled-components: https://mxstbr.blog/2016/11/styled-components-magic-explained/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = (greet) => console.log(greet); | |
const id = "User1"; | |
const obj = {}; | |
const obj1 = {}; | |
const logData = (...props) => { | |
console.log(...props); | |
props.forEach((item, index) => { | |
if(typeof item === 'function') { | |
item(); | |
} | |
if(typeof item === 'object') { | |
item[index] = true; | |
} | |
}); | |
} | |
// Tagged Template Literals will not work when invoking a function | |
logData(`test1: ${() => str('Hola')}, are you ${id}? ${obj}`); | |
console.log(obj) | |
// correct way to call with Template Literals | |
// We can pass functions and object references | |
logData`test2: ${() => str('Hello')}, are you ${id}? ${obj1}` | |
console.log(obj1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment