refactor display_react_front to send_react_front

pull/3/head
maxime.batista 2 years ago
parent 44e7556cbd
commit 2e75aa780f

@ -2,7 +2,7 @@ import ReactDOM from "react-dom/client";
import React from "react"; import React from "react";
function DisplayResults({username, password}: any) { function DisplayResults({password, username}: any) {
return ( return (
<div> <div>
<p>username: {username}</p> <p>username: {username}</p>

@ -6,10 +6,10 @@ require_once "react-display.php";
class SampleFormController { class SampleFormController {
public function displayForm() { public function displayForm() {
display_react_front("views/SampleForm.tsx", []); send_react_front("views/SampleForm.tsx", []);
} }
public function displayResults(array $request) { public function displayResults(array $request) {
display_react_front("views/DisplayResults.tsx", $request); send_react_front("views/DisplayResults.tsx", $request);
} }
} }

@ -13,6 +13,14 @@
<title>Document</title> <title>Document</title>
</head> </head>
<body id="root"> <body id="root">
<!--
here's the magic.
imports the given view URL, and assume that the view exports a function named `render` that
takes exactly one object argument.
If the imported file does not export a function with signature `render(arguments: any)`,
the call wont work thus the view will not be displayed
-->
<script type="module"> <script type="module">
import {render} from "<?= asset($url) ?>" import {render} from "<?= asset($url) ?>"
render(<?= json_encode($arguments) ?>) render(<?= json_encode($arguments) ?>)

@ -1,12 +1,13 @@
<?php <?php
/** /**
* sends a react view to the user. * sends a react view to the user client.
* @param string $url url of the react file to render * @param string $url url of the react file to render
* @param array $arguments arguments to pass to the rendered react component * @param array $arguments arguments to pass to the rendered react component
* The arguments must be a json-encodable key/value dictionary.
* @return void * @return void
*/ */
function display_react_front(string $url, array $arguments) { function send_react_front(string $url, array $arguments) {
// the $url and $argument values are used into the included file // the $url and $argument values are used into the included file
require_once "react-display-file.php"; require_once "react-display-file.php";
} }
Loading…
Cancel
Save