@dswistowski/destiny-manifest-react
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Destiny manifest react

This package contains helper to use destiny manifest in frontend typescript react application.

Installation

npm add @dswistowski/destiny-manifest-react

Usage

  1. Create manifest module with loader:
import {
  createDefaultManifest,
  createLoader,
  inferDomains,
} from "@dswistowski/destiny-manifest-react";

const loader = createLoader()
  .add("DestinyLoreDefinition", ({ hash, displayProperties, index }) => ({
    hash,
    displayProperties,
    index,
  }))
  .add(
    "DestinyInventoryItemDefinition",
    ({ hash, displayProperties, loreHash }) => ({
      hash,
      displayProperties,
    })
  );

export const manifest = createDefaultManifest({
  loader,
  apiKey: process.env.REACT_APP_BUNGIE_API_KEY,
  language: "en",
});

export type Domains = inferDomains<typeof loader>;

And then use it in your application:

import { manifest, Domains } from "./manifest";

const LoreDefinition: React.FC<{ lore: Domains["DestinyLoreDefinition"] }> = ({
  lore,
}) => {
  return (
    <div>
      <h1>{lore.displayProperties.name}</h1>
      <p>{lore.displayProperties.description}</p>
    </div>
  );
};

const ItemDefinition: React.FC<{
  item: Domains["DestinyInventoryItemDefinition"];
}> = ({ item }) => {
  const lore = manifest.useDestinyLoreDefinition(item.loreHash);
  return (
    <div>
      <h1>{item.displayProperties.name}</h1>
      <p>{item.displayProperties.description}</p>
      {lore && <LoreDefinition lore={lore} />}
    </div>
  );
};

const Items: React.FC = () => {
  const items = manifest.useDestinyInventoryItemDefinitions(() => true);
  return (
    <div>
      {items.map((item) => (
        <ItemDefinition key={item.hash} item={item} />
      ))}
    </div>
  );
};

Readme

Keywords

none

Package Sidebar

Install

npm i @dswistowski/destiny-manifest-react

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

2.67 MB

Total Files

5

Last publish

Collaborators

  • dswistowski