Skip to main content

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

@meirdev

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

SignatureDescription
static inflight exec(command: str, env: MutMap, cwd: str): inflight (): void
No description
static execSync(command: str, env: MutMap, cwd: str): void
No description
static inflight serveStaticFiles(path: str, port: num): inflight (): voidNo description

AppTfAws (preflight class)

No description

Constructor

new(props: AppProps): AppTfAws

Properties

No properties

Methods

SignatureDescription
_preSynthesize(): voidNo description
getUrl(): strNo description
addEnvironment(key: str, value: str): voidNo description

AppSim (preflight class)

No description

Constructor

new(props: AppProps): AppSim

Properties

NameTypeDescription
urlstrNo description

Methods

SignatureDescription
getUrl(): strNo description
addEnvironment(key: str, value: str): voidNo description

App (preflight class)

No description

Constructor

new(props: AppProps): App

Properties

NameTypeDescription
urlstrNo description

Methods

SignatureDescription
addEnvironment(key: str, value: str): voidNo description

AppBase (preflight class)

No description

Constructor

new(props: AppProps): AppBase

Properties

No properties

Methods

SignatureDescription
addEnvironment(key: str, value: str): voidNo description

IApp (interface)

No description

Properties

No properties

Methods

SignatureDescription
addEnvironment(key: str, value: str): voidNo description
getUrl(): strNo description

AppProps (struct)

No description

Properties

NameTypeDescription
buildCommandstr?No description
buildDirstr?No description
domainDomain?No description
localPortnum?No description
projectPathstrNo description
startCommandstr?No description
useBuildCommandbool?No description