Last active
May 3, 2020 13:57
-
-
Save greatestview/f6f3f28f80964da54c9bef482eb808c8 to your computer and use it in GitHub Desktop.
Thoughts about how React components could be implemented in PHP
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
<script> | |
import React from 'react'; | |
function Teaser(props) { | |
return ( | |
<div class="teaser"> | |
<h2>{props.title}</h2> | |
<p>{props.text}</p> | |
</div> | |
); | |
} | |
</script> | |
<script> | |
import React from 'react'; | |
function Teaser(props) { | |
return React.createElement( | |
"div", | |
{class: "teaser"}, | |
[ | |
React.createElement( | |
"h2", | |
null, | |
props.title | |
), | |
React.createElement( | |
"p", | |
null, | |
props.text | |
), | |
] | |
); | |
} | |
</script> | |
<?php | |
function Teaser($props) { | |
$title = esc_html($props["title"]); | |
$text = esc_html($props["text"]); | |
$image_url = getImageUrlById($props["imageId"]); | |
return <<<HTML | |
<div class="teaser"> | |
<h2>$title</h2> | |
<img src="$image_url" alt> | |
<p>$text</p> | |
</div> | |
HTML; | |
} | |
// --- | |
include "./Teaser.php"; | |
echo Teaser([ | |
"title" => "Ich bin der Teaser Title", | |
"text" => "Ich bin der Teaser Text", | |
"imageId" => 12 | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment