You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-mapbox-ui

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mapbox-ui

MapboxUI provides a minimal layer of abstraction for composing mapbox-gl UI's in an idiomatic React way.

0.1.3
Source
npmnpm
Version published
Weekly downloads
5
-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

react-mapbox-ui

MapboxUI provides a minimal layer of abstraction for composing mapbox-gl UI's in an idiomatic React way.

This library does not provide out of the box components for mapbox layers, sources, markers, etc. This can easily be achieved with composition. See Usage for an example below.

Install

yarn add react-mapbox-ui
# or
npm i react-mapbox-ui

Usage

See TypeDocs.

Composing your own MapboxUI components.

// ./examples/Marker.tsx
import { MapboxUI, useMapboxUIEffect } from "react-mapbox-ui";
import "mapbox-gl/dist/mapbox-gl.css";

const accessToken = "your access token";

const centerCoorindates: LngLatLike = [-79.347015, 43.65107]; // Toronto

type MarkerProps = { coordinates: LngLatLike };

/**
 * Creating a <Marker/> component.
 * Most of your MapboxUI components will be renderless and hook into MapboxUI context with hooks
 * This allows consumers to manage their own Mapbox side effects with effect lifecycles
 **/
const Marker: React.FC<MarkerProps> = ({ coordinates }) => {
  // useMapboxUIEffect provides you with MapboxUI context wrapped in a useEffect
  useMapboxUIEffect(
    ({ map, mapbox }) => {
      const marker = new mapbox.Marker().setLngLat(coordinates).addTo(map);

      return () => {
        marker.remove();
      };
    },
    [coordinates]
  );

  return null;
};

const App = () => {
  return (
    <MapboxUI
      accessToken={accessToken}
      style={{
        height: "100vh",
        width: "100%",
      }}
      defaultCenter={centerCoorindates}
    >
      <Marker coordinates={centerCoorindates} />
    </MapboxUI>
  );
};

FAQs

Package last updated on 05 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts