1
- import React , { useState } from 'react' ;
1
+ import React , { useRef , useState } from 'react' ;
2
2
import type { NextPage } from 'next' ;
3
3
import { Form , Toggle } from 'react-daisyui' ;
4
4
import { Page , Container , Toolbar , Canvas , Code } from 'components/content' ;
5
- import { View , Layer , Rectangle } from 'react-paper-bindings' ;
5
+ import { PaperScope , View , Layer , Rectangle } from 'react-paper-bindings' ;
6
+
7
+ const MultiCanvasPage : NextPage = ( ) => {
8
+ const [ scope1 ] = useState ( new PaperScope ( ) ) ;
9
+ const scope2 = useRef ( new PaperScope ( ) ) ;
6
10
7
- const MultiCanvas : NextPage = ( ) => {
8
11
const [ visible1 , setVisible1 ] = useState ( true ) ;
9
12
const [ visible2 , setVisible2 ] = useState ( true ) ;
13
+
10
14
const [ color1 , setColor1 ] = useState ( 'blue' ) ;
11
15
const [ color2 , setColor2 ] = useState ( 'red' ) ;
16
+
12
17
return (
13
18
< Page title = "Multi Canvas" >
14
19
< Container >
@@ -29,7 +34,7 @@ const MultiCanvas: NextPage = () => {
29
34
</ Form . Label >
30
35
</ Toolbar >
31
36
{ visible1 && (
32
- < Canvas >
37
+ < Canvas scope = { scope1 } >
33
38
< View >
34
39
< Layer >
35
40
< Rectangle
@@ -43,7 +48,7 @@ const MultiCanvas: NextPage = () => {
43
48
</ Canvas >
44
49
) }
45
50
{ visible2 && (
46
- < Canvas >
51
+ < Canvas scope = { scope2 . current } >
47
52
< View >
48
53
< Layer >
49
54
< Rectangle
@@ -62,19 +67,24 @@ const MultiCanvas: NextPage = () => {
62
67
) ;
63
68
} ;
64
69
65
- export default MultiCanvas ;
70
+ export default MultiCanvasPage ;
66
71
67
- const code = `import React, { useState } from 'react';
72
+ const code = `import React, { useRef, useState } from 'react';
68
73
import type { NextPage } from 'next';
69
74
import { Form, Toggle } from 'react-daisyui';
70
- import { Page, Container, Toolbar, Canvas } from 'components/content';
71
- import { View, Layer, Rectangle } from 'react-paper-bindings';
75
+ import { Page, Container, Toolbar, Canvas, Code } from 'components/content';
76
+ import { Scope, View, Layer, Rectangle } from 'react-paper-bindings';
77
+
78
+ const MultiCanvasPage: NextPage = () => {
79
+ const [scope1] = useState(new Scope());
80
+ const scope2 = useRef(new Scope());
72
81
73
- const MultiCanvas: NextPage = () => {
74
82
const [visible1, setVisible1] = useState(true);
75
83
const [visible2, setVisible2] = useState(true);
84
+
76
85
const [color1, setColor1] = useState('blue');
77
86
const [color2, setColor2] = useState('red');
87
+
78
88
return (
79
89
<Page title="Multi Canvas">
80
90
<Container>
@@ -95,7 +105,7 @@ const MultiCanvas: NextPage = () => {
95
105
</Form.Label>
96
106
</Toolbar>
97
107
{visible1 && (
98
- <Canvas>
108
+ <Canvas scope={scope1} >
99
109
<View>
100
110
<Layer>
101
111
<Rectangle
@@ -109,7 +119,7 @@ const MultiCanvas: NextPage = () => {
109
119
</Canvas>
110
120
)}
111
121
{visible2 && (
112
- <Canvas>
122
+ <Canvas scope={scope2.current} >
113
123
<View>
114
124
<Layer>
115
125
<Rectangle
@@ -127,4 +137,4 @@ const MultiCanvas: NextPage = () => {
127
137
);
128
138
};
129
139
130
- export default MultiCanvas ;` ;
140
+ export default MultiCanvasPage ;` ;
0 commit comments