React
Use React in your project.
Prerequisites
Installation
npm i @winglibs/react
Usage
main.w
:
bring cloud;
bring react;
let api = new cloud.Api(cors: true);
api.get("/", inflight () => {
return {
status: 200,
body: "Hello World! API",
};
});
let project = new react.App(
projectPath: "../react-project",
localPort: 4500,
);
project.addEnvironment("API_URL", api.url);
project.addEnvironment("TEXT", "Hello World!");
Add <script src="./wing.js"></script>
to your index.html
file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<script src="./wing.js"></script>
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
The variables will be available via window.wingEnv
:
import { useEffect, useState } from "react";
function App() {
const [text, setText] = useState("");
const { API_URL, TEXT } = window.wingEnv;
useEffect(() => {
fetch(API_URL).then((response) => {
response.text().then((data) => {
setText(data);
})
});
}, []);
return (
<div className="App">
<p>TEXT: {TEXT}</p>
<p>FROM API: {text}</p>
</div>
);
}
export default App;
Maintainers
License
This library is licensed under the MIT License.
API Reference
Table of Contents
Utils (preflight class)
No description
Constructor
new(): Utils
Properties
No properties
Methods
Signature | Description |
---|---|
| No description |
| No description |
static inflight serveStaticFiles(path: str, port: num): inflight (): void | No description |
AppTfAws (preflight class)
No description
Constructor
new(props: AppProps): AppTfAws
Properties
No properties
Methods
Signature | Description |
---|---|
_preSynthesize(): void | No description |
getUrl(): str | No description |
addEnvironment(key: str, value: str): void | No description |
AppSim (preflight class)
No description
Constructor
new(props: AppProps): AppSim
Properties
Name | Type | Description |
---|---|---|
url | str | No description |
Methods
Signature | Description |
---|---|
getUrl(): str | No description |
addEnvironment(key: str, value: str): void | No description |
App (preflight class)
No description
Constructor
new(props: AppProps): App
Properties
Name | Type | Description |
---|---|---|
url | str | No description |
Methods
Signature | Description |
---|---|
addEnvironment(key: str, value: str): void | No description |
AppBase (preflight class)
No description
Constructor
new(props: AppProps): AppBase
Properties
No properties
Methods
Signature | Description |
---|---|
addEnvironment(key: str, value: str): void | No description |
IApp (interface)
No description
Properties
No properties
Methods
Signature | Description |
---|---|
addEnvironment(key: str, value: str): void | No description |
getUrl(): str | No description |
AppProps (struct)
No description
Properties
Name | Type | Description |
---|---|---|
buildCommand | str? | No description |
buildDir | str? | No description |
domain | Domain? | No description |
localPort | num? | No description |
projectPath | str | No description |
startCommand | str? | No description |
useBuildCommand | bool? | No description |