How to use the @wq/react.useApp function in @wq/react

To help you get started, we’ve selected a few @wq/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wq / wq.app / packages / map / src / hooks.js View on Github external
export function useGeoJSON(url, data, asFeatureCollection) {
    const app = useApp(),
        [geojson, setGeojson] = useState();

    if (!(url.indexOf('/') === 0 || url.indexOf('http') === 0)) {
        console.warn(new Error(`Use "{{rt}}/${url}" instead of relative URL`));
        url = app.service + '/' + url;
    }

    useEffect(() => {
        if (data) {
            setGeojson(parseGeojson(data, asFeatureCollection));
            return;
        }
        if (_cache[url]) {
            setGeojson(parseGeojson(_cache[url], asFeatureCollection));
            return;
        }