Created
January 27, 2018 21:35
-
-
Save baransu/728eb1889def9bf474cc370862581d6e to your computer and use it in GitHub Desktop.
This file contains 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 WithColor = ({ children }) => { | |
const color = /* advanced compuation as fuck */ | |
return children(color); | |
} | |
// nasz Component ktory korzysta z render propsow | |
const Component = () => { | |
render ( | |
<WithColor> | |
// jesli cokolwiek co jest miedzy tagiem jest przekazywane jaki children to mozna zrobic z tym cokolwiek | |
// wiec mozna przekazac funkcje na przyklad | |
// to nie bedzie dzialac w reasonie bo on spodziewa sie array(a) | |
{(color) => <button style={{ color }}/>} | |
</WithColor> | |
) | |
} | |
// alternatywna skladnia ktora bedzie juz dzialac w reasonie | |
// przewaznie uzywa sie do tego children i/lub render property wiec pol biedy tak na prawde | |
const Component = () => { | |
render ( | |
<WithColor render={color => <button style={{ color }}/>)/> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment