Skip to content

Commit

Permalink
Merge pull request #277 from dojoengine/feat/sdk-example
Browse files Browse the repository at this point in the history
fix: prettier
  • Loading branch information
ponderingdemocritus authored Sep 25, 2024
2 parents 105af37 + c1dc5b6 commit 58bda16
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
43 changes: 8 additions & 35 deletions examples/example-vite-react-sdk/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
import { useEffect, useState } from "react";

import "./App.css";
import { ParsedEntity, SDK } from "@dojoengine/sdk";
import { Schema } from "./bindings.ts";

import { init, ParsedEntity } from "@dojoengine/sdk";

import { dojoConfig } from "../dojoConfig.ts";
import { Schema, schema } from "./bindings.ts";

const db = await init<Schema>(
{
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress:
"0x5d475a9221f6cbf1a016b12400a01b9a89935069aecd57e9876fcb2a7bb29da",
},
domain: {
name: "Example",
version: "1.0",
chainId: "your-chain-id",
revision: "1",
},
},
schema
);

function App() {
function App({ db }: { db: SDK<Schema> }) {
const [entities, setEntities] = useState<ParsedEntity<Schema>[]>([]);

useEffect(() => {
Expand All @@ -37,13 +14,7 @@ function App() {
{
dojo_starter: {
Moves: {
$: {
where: {
player: {
$is: "0x3628a39cc6bd2347e79967e9458ac41ab65bac6949f2aa311b311aff0d7334d",
},
},
},
$: {},
},
},
},
Expand Down Expand Up @@ -81,7 +52,9 @@ function App() {
unsubscribe();
}
};
}, []);
}, [db]);

console.log("entities:");

useEffect(() => {
const fetchEntities = async () => {
Expand Down Expand Up @@ -129,7 +102,7 @@ function App() {
};

fetchEntities();
}, []);
}, [db]);

return (
<div>
Expand Down
37 changes: 32 additions & 5 deletions examples/example-vite-react-sdk/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,36 @@ import { createRoot } from "react-dom/client";
import App from "./App.tsx";

import "./index.css";
import { init } from "@dojoengine/sdk";
import { Schema, schema } from "./bindings.ts";
import { dojoConfig } from "../dojoConfig.ts";

createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>
);
async function main() {
const db = await init<Schema>(
{
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
},
domain: {
name: "Example",
version: "1.0",
chainId: "your-chain-id",
revision: "1",
},
},
schema
);

createRoot(document.getElementById("root")!).render(
<StrictMode>
<App db={db} />
</StrictMode>
);
}

main().catch((error) => {
console.error("Failed to initialize the application:", error);
});

0 comments on commit 58bda16

Please sign in to comment.