npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-mem-api

v0.1.0

Published

<p align="center"> <a href="https://decent.land"> <img src="https://mem-home.vercel.app/icons/mem/mem-logo-v2.svg" height="180"> </a> <h3 align="center"><code>@decentldotland/react-mem-js</code></h3> <div align="center">Your easiest foray into

Downloads

4

Readme

Overview

  • Lightweight

We've made sure unecessary bloat is kept at bay. Check out the package size:

  • Fast setup

All you need to get started with is within the useMEM hook:

export default function Homepage() {
  const shop = useMEM("xyz1...1yzq");

  const buyItem = async (item) => {
    const result = await shop.write([{ input: { function: "buy", item } }]);
    const errors = Object.keys(result.data.execution.errors);
    if (!errors.length) console.log("Successfully purchased " + item)
    else console.error("Couldn't buy " + item)
  }

  return (
    <div>
      <div>
        <p>Hockey Puck</p>
        <button onClick={() => buyItem("Hockey Puck")}>Buy</button>
      </div>
      <div>
        <p>Helmet</p>
        <button onClick={() => buyItem("Helmet")}>Buy</button>
      </div>
    </div>
  )
}

Install

Add it to your project:

# npm
npm install react-mem-js

# yarn
yarn add react-mem-js

# pnpm
pnpm add react-mem-js

# bun
bun add react-mem-js

Setup

First, let's wrap the app with our provider:



// If you're using next.js, this should be your _app.tsx file
import React from 'react';

import { MEMContext } from "react-mem-js";
import "../styles/globals.css";

function ExampleApp({ Component, pageProps }) {
  return (
    <MEMContext.Provider value={{}}>
      <Component {...pageProps} />
    </MEMContext.Provider>
  );
}

export default ExampleApp;

Then, within your app, call useMEM:

export default function Home() {
  const library = useMEM("yBgIzbc3lvwlBjw6V-G9Woy5Hx2uY37aDQIPoQ5kRRw");

  const [books, setBooks] = useState([]);
  
  return (
    <div>
      {books?.length > 0 && (
        books.map(bookName => <div>{bookName}</div>)
      )}
    </div>
  )
}

Examples

Check out the example Next.js app.

API

MEMContext

A wrapper around useContext that manages the store of MEM instances. Doesn't accept any arguments.

// Next.js
<MEMContext.Provider value={{}}>
  <Component {...pageProps} />
</MEMContext.Provider>

currentFunction

Returns the current function being used in mem-js

setFunctionId

Swaps the functionID used in MEM

destroyFunctionId

Delete the functionId inside the MEM store.

allFunctions

Returns all currently tracked MEM instances. Each one is accessible via the functionId as the key and implement MEMInstance interface.

state

Return latest state of a function as parsed JSON object.

read

Query a function. Accept another functionId as argument:

const { read, state } = useMEM("241-...djKK");
// reads and saves to local state
console.log(await read());
// reading other function ID, won't be saved in local state
console.log(await read("AI-F...La2T"));

write

Write to function. Accepts input and otherFunctionId Params.

const { write } = useMEM("241-...djKK");
const result = await write([{ input: { function: "save", bookName } }]);
console.log(result);

testnet

Test functions and their parameters in a MEM-sandbox environment. Example:

const { testnet } = useMEM();

const contractType = 0; // Language, 0 is JavaScript
const initState = JSON.stringify({ name: "Carl", publicFunctions: { changeName: ["newName"] } })
const input = JSON.stringify({ function: "changeName", newName: "Lukas (Computer)" })
const contractSrc = `
export async function handle(state, action) {
  const input = action.input;
  if (input.function === "save") {
    const { newName } = input;
    const nameLength = newName.trim().length;
    ContractAssert(!!nameLength, "Error: No newName provided");
    state.name = newName;
    // this is important: without it, function invokation won't return the state
    return { state };
  }
}
`

const options = {
  contractType,
  initState,
  input,
  contractSrc,
};
const result = await testnet(options);
// will output new state object, have to manually compare changes

Roadmap

Step 1: Core API built ✅ Step 2: Add everpay.js and arseed file uploading helpers for MEM ⏳ Step 3: Wallet APIs like ETH, SOL, and more 🔜

License

This project is licensed under the MIT license