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

@nice-xrpl/react-xrpl

v4.0.0

Published

React-xrpl is a set of hooks and components for creating applications using xrpl.js in React. This library abstracts away parts of the xrpl.js API in order to provide a set of reactive hooks and components to interact with wallets complete with escape ha

Downloads

113

Readme

react-xrpl

React-xrpl is a set of hooks and components for creating applications using xrpl.js in React. This library abstracts away parts of the xrpl.js API in order to provide a set of reactive hooks and components to interact with wallets complete with escape hatches to use the native API if needed!

Getting Started

npm install react-xrpl

This will install the library and all dependencies. In order to simplify installation and not require changes to any of your tooling configuration (webpack, vite, etc.), we have opted to include and bundle the xrpl.js library with react-xrpl. Please keep this in mind if you have installed xrpl.js separately, as react-xrpl will NOT use it. We are working to alleviate this requirement and allow xrpl.js as a peer dependency.

NOTE: V1 is a major breaking change from older 0.0.x releases.

Your first application

Any components that make use of any provided hooks/components need to be wrapped in a client.

import { XRPLClient } from '@nice-xrpl/react-xrpl';

function Main() {
	return (
		<XRPLClient>
			<App />
		</XRPLClient>
	);
}

You can now start using the various hooks and components present in the library! General purpose hooks, such as useIsConnected may be used within the scope of XRPLClient. However, any request hooks require an Account component to be present and any transaction hooks require a Wallet component to be present. Account provides reactive usage of all request hooks.

Here is a simple example using Account:

import { Account } from '@nice-xrpl/react-xrpl'

function App() {
	const myAddress = 'test address';

	return (
		<Account address={myAddress}>
			<ShowBalance />
		</Account>
	);
}

function ShowBalance() {
	const balance = useBalance();

	return (
		<div>Balance: {balance}</div>
	);
}

Wallet accepts a seed or secret, or will generate a new seed from entropy. Wallets provide credentials and are the only way to use transaction hooks (such as sending xrp). On testnet, the useFundWallet hook may be used to seed xpr from a faucet. You can also use the Account component inside a Wallet in order to use request hooks. If used inside a Wallet, you do not need to provide an address to Account. Keep in mind that an Account must be valid for the account component to work - if the account has not been funded, then Account will throw an error that needs to be caught by an ErrorBoundary.

import { Wallet } from '@nice-xrpl/react-xrpl'

function App() {
	const mySeed = 'test seed';

	return (
		<Wallet address={mySeed}>
			<Account>
				<SendXRP />
			</Account>
		</Wallet>
	);
}

function SendXRP() {
	const sendXRP = useSendXRP();
	const balance = useBalance();

	return (
		<div><button onClick={async () => {
			const result = await sendXRP('destination address', 48);
		}}>Send XRP</button></div>
		<div>My Balance: {balance}</div>
	);
}

License

ISC License

Copyright (c) 2012-2021 Contributers to xrpl.js

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.