1.0.53 • Published 6 months ago

wapplr-react v1.0.53

Weekly downloads
60
License
MIT
Repository
github
Last release
6 months ago

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

6 months ago

1.0.51

6 months ago

1.0.50

6 months ago

1.0.53

6 months ago

1.0.52

6 months ago

1.0.48

7 months ago

1.0.47

7 months ago

1.0.46

8 months ago

1.0.45

8 months ago

1.0.44

1 year ago

1.0.39

2 years ago

1.0.40

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.38

2 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago