-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathdeepThought.js
45 lines (38 loc) · 1.27 KB
/
deepThought.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import { useState, useEffect } from 'react'
import { dotnet } from '@microsoft/dotnet-runtime'
let dotnetRuntimePromise = undefined;
async function createRuntime() {
try {
return dotnet.
withModuleConfig({
locateFile: (path, prefix) => {
return '/' + path;
}
})
.create();
} catch (err) {
console.error(err);
throw err;
}
}
async function dotnetMeaning() {
if (!dotnetRuntimePromise) {
dotnetRuntimePromise = createRuntime();
}
const { getAssemblyExports } = await dotnetRuntimePromise;
const exports = await getAssemblyExports("Wasm.Browser.NextJs.Sample.dll");
return exports.Sample.Test.Main();
}
export default function DeepThought() {
const [meaning, setCount] = useState(undefined);
useEffect(async () => {
const meaning = await dotnetMeaning();
setCount(meaning);
}, []);
if (!meaning) {
return (<div>DeepThought is thinking ....</div>);
}
return (<div>Answer to the Ultimate Question of Life, the Universe, and Everything is : {meaning}!</div>);
};