wapplr-react

1.0.53 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.533latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.533
1.0.520
1.0.510
1.0.500
1.0.490
1.0.480
1.0.470
1.0.460
1.0.450
1.0.440
1.0.430
1.0.420
1.0.410
1.0.400
1.0.391
1.0.380
1.0.370
1.0.360
1.0.350
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.280
1.0.270
1.0.260
1.0.250
1.0.240
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i wapplr-react

Weekly Downloads

4

Version

1.0.53

License

MIT

Unpacked Size

61.3 kB

Total Files

14

Last publish

Collaborators

  • c4rc0