Add React Support #3
Merged
maxime.batista
merged 12 commits from setup-typescript-react
into master
1 year ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'setup-typescript-react'
Deleting a branch is permanent. It CANNOT be undone. Continue?
As the editor and visualizer features of the project will require a significant amount of front-end work, we'll use the react framework and TypeScript to achieve our views.
This pull request adds TypeScript/React to the project, and a Continuous Deployment (CD) workflow to automatically deploy the website on our staging server (https://maxou.dev/IQBall/public) when the
master
branch gets new commits pushed.Folder tree of the project
The Folder tree was updated, here are the goals of each directories.
How does php sends react views to the client
As our views are now done using react (and defined under the
front/views
folder), we need to use thesend_react_front($viewURI, $viewArguments)
php function (located in thesrc/react-render.php
file).As there is nothing serious on the master branch regarding the project views, a sample controller (
src/Controller/SampleFormController.php
) with a form view (front/views/SampleForm.tsx
) and a view that displays the information entered in the form (front/views/DisplayResult
) has been made to let you understand how to use thesend_react_front
function to render the react views and how to bind data to the views.React views conventions.
Conventions regarding our react views must be respected in order to be renderable.
If you look at the
send_react_front($viewURI, $viewArguments)
function, you'll see that is simply loads the filesrc/react-display-file.php
with given arguments.The file is a simple html5 template with a
<script>
block in the<body>
section. The script block imports the requested view and will render it using a specificrender(any)
function. This function must figure in the imported view file in order to work.The
render(any)
functionany react view file should export a function with signature
render(arguments: any)
, which responsibility is to render the view.The
arguments
parameter is used to pass data to the react component.If you take a look at the
front/views/SampleForm.tsx
view, here's the definition of its render function :Pass arguments to our react views
We'll take the example of the view in charge of displaying the SimpleForm's fields values.
First, let's take a look at its React Component definition :
The components takes two arguments, a
username
andpassword
string.Now, let's take a look at its
render
function :let's take a look at this line:
DisplayResults
is the name of our React Component (the function).To pass arguments to the
DisplayResults
function, we use the syntax<function parameter name>={value}
. (somewhat like regular html/xml components).Use the render's function
args
parameter to access to the php's array values (see below).So now we have defined our react view, let's send it to the user's browser from php.
To render the
DisplayResults
view, we'll use thesend_react_front()
:NOTE: in the project, the
$_POST
is placed instead of the hardcoded array, as the$_POST
is an array containing the "name" and "password" keys. (regarding the SampleForm's form inputs names)).Add React Supportto WIP: Add React Support 2 years ago7124a5ff06
to6f0d82fb2b
2 years ago6f0d82fb2b
to7cd2e4603a
2 years agoWIP: Add React Supportto Add React Support 2 years agobdc9bfc1cb
to106ef8ea1d
2 years ago5e60438c48
tod08362afc4
1 year ago35ee995fef
to3de6743242
1 year ago3de6743242
to88c5b326fe
1 year ago0a8edb0841
toe1f635c5dc
1 year agoe1f635c5dc
to03873bd5f7
1 year agoConventions regarding our react views __must be respected in order to be renderable__.
### The `render(any)` function
__any react view file__ should __export__ a function with signature `render(arguments: any)`, which responsibility is to render the view.
"App\\": "src/"
}
},
"include-path": ["src"],
It is deprecated.
import ReactDOM from "react-dom/client";
import React, {FunctionComponent} from "react";
import ReactDOM from "react-dom/client";
import React from "react";
The React import can be omitted since React 17.
import React from "react";
import ReactDOM from "react-dom/client";
The React import can be omitted since React 17.
"@types/react-dom": "^18.2.14",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^4.9.5",
"react-app/jest"
]
},
"browserslist": {
browserslist
is not read by Vite./**
* relative path of the index.php's directory from the server's document root.
*/
global $basePath;
This is already a global variable since it is at the root scope.
if ($match == null) {
// TODO redirect to a 404 not found page instead (issue #1)
echo "page non trouvée";
header('HTTP/1.1 404 Not Found');
Headers must be sent before any content.
}
?>
window.__vite_plugin_react_preamble_installed__ = true
This belongs to the
SUPPORTS_FAST_REFRESH
conditional.<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body id="root">
Attaching React to the body is not recommended.
c2bd07db78
toe7f5cc72c5
1 year agoa20562dee7
to9aea5bd80f
1 year ago9aea5bd80f
to7df33f32b5
1 year ago5fe901253c
into master 1 year agoReviewers
5fe901253c
.