Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to React 18 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ See [Tutorial here](https://medium.com/@rocketlaunchr.cloud/go-with-react-de5ee4

## Dependencies

- [React 16.5.2](https://www.npmjs.com/package/react) (it will probably work with lower)
- [React 18.2.0](https://www.npmjs.com/package/react) (it will probably work with lower)
- [Gopherjs](https://github.com/gopherjs/gopherjs) (Go to Javascript transpiler)
- [create-react-class](https://www.npmjs.com/package/create-react-class)
- [react-addons-pure-render-mixin](https://www.npmjs.com/package/react-addons-pure-render-mixin) (optional: For creating a `PureComponent`)
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handling/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func main() {
domTarget := react.GetElementByID("app")
domTarget := react.CreateRoot(react.GetElementByID("app"))

// An example using Functional Components
// See: https://reactjs.org/docs/components-and-props.html
Expand Down
2 changes: 1 addition & 1 deletion examples/uptime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func main() {
domTarget := react.GetElementByID("app")
domTarget := react.CreateRoot(react.GetElementByID("app"))

title := "UPTIME TIMER"

Expand Down
14 changes: 8 additions & 6 deletions react.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ func GetElementByID(id string, dom ...*js.Object) *js.Object {
return js.Global.Get("document").Call("getElementById", id)
}

// Render will render component to the specified target dom element.
func Render(element *js.Object, domTarget *js.Object, 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)
// CreateRoot will create a root from the specified target dom element.
func CreateRoot(domTarget *js.Object) *js.Object {
return ReactDOM.Call("createRoot", domTarget)
}

// Render will render component to the specified root.
func Render(element *js.Object, domTarget *js.Object) *js.Object {
return domTarget.Call("render", element)
}