-
Notifications
You must be signed in to change notification settings - Fork 11
/
react.go
28 lines (25 loc) · 920 Bytes
/
react.go
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
package react
import (
"github.com/gopherjs/gopherjs/js"
"honnef.co/go/js/dom"
)
var (
// React points to the React library. Change it
// if it is not in your global namespace.
// See: https://www.npmjs.com/package/react
React = js.Global.Get("React")
// ReactDOM points to the ReactDOM library. Change it
// if it is not in your global namespace.
// See: https://www.npmjs.com/package/react-dom
ReactDOM = js.Global.Get("ReactDOM")
// CreateReactClass points to create-react-class module.
// See: https://www.npmjs.com/package/create-react-class
CreateReactClass = js.Global
)
// Render will render component to the specified target dom element.
func Render(element *js.Object, domTarget dom.Element, callback ...func()) *js.Object {
if len(callback) > 0 && callback[0] != nil {
return ReactDOM.Call("render", element, domTarget, callback[0])
}
return ReactDOM.Call("render", element, domTarget)
}