-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathScopeExample.tsx
More file actions
30 lines (26 loc) · 632 Bytes
/
ScopeExample.tsx
File metadata and controls
30 lines (26 loc) · 632 Bytes
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
import React, { useState } from 'react'
import { usePython } from '@site/../dist'
export default function ScopeExample() {
const { getGlobal, setGlobal } = usePython()
const [x, setX] = useState()
return (
<div className="mb-10">
<h2>Scope</h2>
<button
onClick={async () => {
try {
const g = await getGlobal('x')
console.log('g', g)
setX(g)
} catch (error) {
console.error('err getting g', error)
}
}}
>
Get x
</button>
<br />
<span>x: {JSON.stringify(x)}</span>
</div>
)
}