0.1.30 • Published 1 year ago
@verygoodgraphics/vgg-react v0.1.30
VGG React
Environment
Create a .env file and set the VGG runtime URL if you want to use a specific version, otherwise it will use the latest version.
# Open your terminal and goto the root directory of your project
cp /packages/react/.env.example /packages/react/.envUsage
<VGGRender />
import { VGGRender } from "@verygoodgraphics/vgg-react"
return (
<VGGRender
src="https://raw.githubusercontent.com/verygoodgraphics/vgg_docs/main/static/example/docs__example__vgg_homepage_v1.daruma"
canvasStyle={{
width: "50vw",
height: "100vh",
}}
onLoad={async (_, instance) => {
instance.$("2:94").on(EventType.Click, async () => {
window.alert("Hello, VGG!")
})
}}
/>
)useVGG()
import { useVGG } from "@verygoodgraphics/vgg-react"
const { canvasRef, vgg, isLoading } = useVGG({
src: "https://raw.githubusercontent.com/verygoodgraphics/vgg_docs/main/static/example/docs__example__vgg_homepage_v1.daruma",
})
useEffect(() => {
if (isLoading || !vgg.current) return
vgg.current?.$("2:94").on(EventType.Click, async () => {
window.alert("Hello, VGG!")
})
}, [isLoading])
return (
<canvas
ref={canvasRef}
style={{
width: "50vw",
height: "100vh",
}}
/>
)API
Options for useVGG()
| Option | Type | Required | Default |
|---|---|---|---|
| src | string | Int8Array | ✅ | - |
| runtime | string | - | https://s5.vgg.cool/runtime/latest |
| editMode | boolean | - | false |
| verbose | boolean | - | false |
| disableLoader | boolean | - | false |
| customFonts | string[] | - | [] |
| onLoad | (event: VGGEvent, instance: VGG<T>) => Promise<void> | - | - |
| onLoadError | (event: VGGEvent) => Promise<void> | - | - |
| onReady | EventCallback | - | - |
| onRendered | EventCallback | - | - |
| onStateChange | (event: VGGEvent, instance: VGG<T>) => Promise<void> | - | - |
| onSelect | EventCallback | - | - |
| onLoadingStateUpdate | (state: LoadingState) => void | - | - |
Props for <VGGRender />
| Option | Type | Required | Default |
|---|---|---|---|
| src | string | Int8Array | ✅ | - |
| runtime | string | - | https://s5.vgg.cool/runtime/latest |
| canvasStyle | React.CSSProperties | - | - |
| editMode | boolean | - | false |
| verbose | boolean | - | false |
| disableLoader | boolean | - | false |
| customFonts | string[] | - | [] |
| onLoad | (event: VGGEvent, instance: VGG<T>) => Promise<void> | - | - |
| onLoadError | (event: VGGEvent) => Promise<void> | - | - |
| onReady | EventCallback | - | - |
| onRendered | EventCallback | - | - |
| onStateChange | (event: VGGEvent, instance: VGG<T>) => Promise<void> | - | - |
| onSelect | EventCallback | - | - |
| onLoadingStateUpdate | (state: LoadingState) => void | - | - |
0.1.30
1 year ago
0.1.27
1 year ago
0.1.28
1 year ago
0.1.29
1 year ago
0.1.26
1 year ago
0.1.25
2 years ago
0.1.24
2 years ago
0.1.23
2 years ago
0.1.21
2 years ago
0.1.22
2 years ago
0.1.20
2 years ago
0.1.19
2 years ago
0.1.18
2 years ago
0.1.17
2 years ago
0.1.15
2 years ago
0.1.16
2 years ago
0.1.14
2 years ago
0.1.13
2 years ago
0.1.10
2 years ago
0.1.11
2 years ago
0.1.12
2 years ago
0.1.8
2 years ago
0.1.7
2 years ago
0.1.9
2 years ago
0.1.6
2 years ago
0.1.2
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.5
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago
0.0.11
2 years ago
0.0.12
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.5
2 years ago
0.0.6
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago