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";
function DisplayResults({username, password}: any) {
function DisplayResults({password, username}: any) {
return (
<div>
<p>username: {username}</p>

@ -6,10 +6,10 @@ require_once "react-display.php";
class SampleFormController {
public function displayForm() {
display_react_front("views/SampleForm.tsx", []);
send_react_front("views/SampleForm.tsx", []);
}
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>
</head>
<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">
import {render} from "<?= asset($url) ?>"
render(<?= json_encode($arguments) ?>)

@ -1,12 +1,13 @@
<?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 array $arguments arguments to pass to the rendered react component
* The arguments must be a json-encodable key/value dictionary.
* @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
require_once "react-display-file.php";
}
Loading…
Cancel
Save