🚀 Use Lanyard API easily in your React app!
GPL-3.0 License
yarn add react-use-lanyard
npm i react-use-lanyard
Using without websocket:
import { useLanyard } from "react-use-lanyard";
function App() {
const lanyard = useLanyard({
userId: "952574663916154960",
});
return (
<pre>{!lanyard.isValidating && JSON.stringify(lanyard, null, 4)}</pre>
);
}
export default App;
Using with websocket:
import { useLanyard } from "react-use-lanyard";
function App() {
const { loading, status /*, websocket */ } = useLanyard({
userId: "952574663916154960",
socket: true,
});
return <pre>{!loading && JSON.stringify(status, null, 4)}</pre>;
}
export default App;
You can create/delete KV pairs using this package.
import { set, del } from "react-use-lanyard";
// Set KV pair
await set({
apiKey: "your_api_key", // get it using .apikey command on lanyard bot
userId: "your_user_id",
key: "test_key",
value: "test value",
// apiUrl: "lanyard.338.rocks", // if you are using self-hosted api, not required by default
});
// Delete KV pair
await del({
apiKey: "your_api_key",
userId: "your_user_id",
key: "test_key",
// apiUrl: "lanyard.338.rocks", // if you are using self-hosted api, not required by default
});
You can use this package to connect to your own self-hosted Lanyard API. To do this, you need to pass the apiUrl
option to the useLanyard
hook. See Lanyard self-hosting guide for more information.
Using without websocket:
import { useLanyard } from "react-use-lanyard";
function App() {
const lanyard = useLanyard({
userId: "952574663916154960",
apiUrl: "lanyard.338.rocks",
});
return (
<pre>{!lanyard.isValidating && JSON.stringify(lanyard, null, 4)}</pre>
);
}
export default App;
Using with websocket:
import { useLanyard } from "react-use-lanyard";
function App() {
const { loading, status /*, websocket */ } = useLanyard({
userId: "952574663916154960",
socket: true,
apiUrl: "lanyard.338.rocks",
});
return <pre>{!loading && JSON.stringify(status, null, 4)}</pre>;
}
export default App;
Copyright © 2021 Barış DEMİRCİ.
Distributed under the GPL-3.0 License. See LICENSE
for more information.
Feel free to use GitHub's features.
git checkout -b feature/my-feature
)npm run format && npm run lint
)git commit -m 'my awesome feature my-feature'
)git push origin feature/my-feature
)Give a ⭐️ if this project helped you!