1.0.53 • Published 2 years ago
wapplr-react v1.0.53
Wapplr-react
This package is the React extension for Wapplr.
//server.js
import wapplrReact from "wapplr-react";
import wapplrServer from "wapplr";
const wapp = wapplrServer({config: {
globals: {
WAPP: "yourBuildHash",
ROOT: __dirname
}
}
});
wapplrReact({wapp});
wapp.server.listen();
//client.js
import wapplrReact from "wapplr-react";
import wapplrClient from "wapplr";
const wapp = wapplrClient({config: {
globals: {
WAPP: "yourBuildHash"
}
}
});
wapplrReact({wapp});
wapp.client.listen();
//app.js
import App from "./App";
export default function setContents(p = {}) {
const {wapp} = p;
wapp.contents.add({
home: {
render: App,
description: "My React app",
renderType: "react"
}
})
wapp.router.replace([
{path: "/", contentName: "home"}
])
wapp.router.add([
{path: "/about", contentName: "home"},
{path: "/contact", contentName: "home"},
])
}
//App.js
import React, {useContext, useState, useEffect} from "react";
import getUtils from "wapplr-react/dist/common/Wapp/getUtils";
import {WappContext} from "wapplr-react/dist/common/Wapp";
import style from "./app.css";
export default function App(props) {
const context = useContext(WappContext);
const {wapp} = context;
const utils = getUtils(context);
const {subscribe} = props;
wapp.styles.use(style);
const [url, setUrl] = useState(utils.getRequestUrl());
function onLocationChange(newUrl){
if (url !== newUrl){
setUrl(newUrl);
}
}
useEffect(function (){
const unsub = subscribe.locationChange(onLocationChange);
return function useUnsubscribe(){
unsub();
}
}, [url])
return (
<div className={style.app}>
{url}
</div>
);
}
/*app.css*/
.app {
color: black;
}
License
MIT
1.0.49
2 years ago
1.0.51
2 years ago
1.0.50
2 years ago
1.0.53
2 years ago
1.0.52
2 years ago
1.0.48
2 years ago
1.0.47
2 years ago
1.0.46
2 years ago
1.0.45
2 years ago
1.0.44
2 years ago
1.0.39
3 years ago
1.0.40
3 years ago
1.0.43
3 years ago
1.0.42
3 years ago
1.0.41
3 years ago
1.0.38
4 years ago
1.0.33
4 years ago
1.0.32
4 years ago
1.0.37
4 years ago
1.0.36
4 years ago
1.0.35
4 years ago
1.0.31
4 years ago
1.0.30
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.26
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.23
4 years ago
1.0.29
4 years ago
1.0.28
4 years ago
1.0.27
4 years ago
1.0.20
4 years ago
1.0.19
4 years ago
1.0.18
4 years ago
1.0.17
4 years ago
1.0.16
4 years ago
1.0.15
4 years ago
1.0.14
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.2
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago