@@ -52,12 +52,94 @@ export default TestingPack
52
52
```
53
53
54
54
- if you are using this with forms
55
- - change as following
55
+ - follow the following exmple
56
56
57
57
``` jsx
58
- < div>
59
- < Editor onChange= {} value= {}/ >
60
- < / div>
58
+ import React , { useEffect , useState } from ' react'
59
+ import { Editor } from ' js-wysiwyg-editor'
60
+ import axios from ' axios'
61
+
62
+ const TestingPack = () => {
63
+ // send backend
64
+ const [EditorData , SetEditorData ] = useState ({
65
+ title: ' ' ,
66
+ })
67
+
68
+ const [text , setText ] = useState (' ' );
69
+
70
+ // headleSubmit
71
+
72
+ const headleSubmit = async (e ) => {
73
+ e .preventDefault ()
74
+
75
+ try {
76
+ const res = await axios .post (' http://localhost:8081/AddEditorData' , {EditorData, text})
77
+ .then (res => {
78
+ if (res .data .Status === " Success" ){
79
+ alert (" Editor Data Added Successful" )
80
+ window .location .reload ()
81
+ }
82
+ else {
83
+ alert (res .data .Error )
84
+ }
85
+ })
86
+ }
87
+ catch (err) {
88
+ console .log (err)
89
+ }
90
+ }
91
+
92
+ const [GetData , SetGetData ] = useState ([])
93
+
94
+ useEffect (() => {
95
+ axios .get (' http://localhost:8081/DisplayData' )
96
+ .then (res => SetGetData (res .data .Result ))
97
+ .catch (err => console .log (err))
98
+ }, [])
99
+
100
+
101
+
102
+ return (
103
+ < div className= ' my-8 mx-12' >
104
+ < form onSubmit= {headleSubmit}>
105
+ < input type= " text" name= " " id= " " className= ' h-12 bg-gray-200 rounded'
106
+ onChange= {e => SetEditorData ({... EditorData, title: e .target .value })}/ >
107
+
108
+
109
+ < div className= " " >
110
+ < Editor dataValue= {text} OutputTest= {setText}/ >
111
+ < / div>
112
+
113
+
114
+ < button type= " submit" className= " py-2 px-8 bg-blue-500 text-white rounded" > Submit< / button>
115
+ < / form>
116
+
117
+
118
+ < div className= " w-full p-2 bg-white border border-gray-300 rounded-md shadow-sm" >
119
+ < div dangerouslySetInnerHTML= {{ __html: text .replace (/ \*\* (. *? )\*\* / g , ' <b>$1</b>' ) }} / >
120
+ < / div>
121
+
122
+ < div className= " my-8" >
123
+ < div className= " bg-gray-200 rounded py-2 px4" >
124
+ {
125
+ GetData .map ((Data , index ) => {
126
+ return (
127
+ < div className= " " >
128
+ < h1 className= " " > {Data .editor_title }< / h1>
129
+ < p className= " " >
130
+ < div dangerouslySetInnerHTML= {{ __html: Data .editor_data .replace (/ \*\* (. *? )\*\* / g , ' <b>$1</b>' ) }} / >
131
+ < / p>
132
+ < / div>
133
+ )
134
+ })
135
+ }
136
+ < / div>
137
+ < / div>
138
+ < / div>
139
+ )
140
+ }
141
+
142
+ export default TestingPack
61
143
62
144
```
63
145
0 commit comments