diff --git a/helpers.go b/helpers.go index 34d6765..08fa7e8 100644 --- a/helpers.go +++ b/helpers.go @@ -8,6 +8,7 @@ import ( // Fragment is used to group a list of children // without adding extra nodes to the DOM. +// // See: https://reactjs.org/docs/fragments.html func Fragment(key *string, children ...interface{}) *js.Object { props := map[string]interface{}{} @@ -38,12 +39,14 @@ func JSFn(name string, args ...interface{}) *js.Object { } // CreateRef will create a Ref. +// // See: https://reactjs.org/docs/refs-and-the-dom.html func CreateRef() *js.Object { return React.Call("createRef") } // ForwardRef will forward a Ref to child components. +// // See: https://reactjs.org/docs/forwarding-refs.html func ForwardRef(component interface{}) *js.Object { return React.Call("forwardRef", func(props *js.Object, ref *js.Object) *js.Object { @@ -67,6 +70,7 @@ func ForwardRef(component interface{}) *js.Object { // CreateContext is used when you want to pass data to a deeply // embedded child component without using props. +// // See: https://reactjs.org/docs/context.html#reactcreatecontext func CreateContext(defaultValue ...interface{}) (Provider *js.Object, Consumer *js.Object) { @@ -82,6 +86,7 @@ func CreateContext(defaultValue ...interface{}) (Provider *js.Object, Consumer * } // CloneElement is used to clone and return a new React Element. +// // See: https://reactjs.org/docs/react-api.html#cloneelement func CloneElement(element interface{}, props interface{}, children ...interface{}) *js.Object { diff --git a/react.go b/react.go index c8ff92f..bc1bcff 100644 --- a/react.go +++ b/react.go @@ -10,13 +10,16 @@ import ( 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 ) diff --git a/react_class.go b/react_class.go index c266cb7..56f6d9e 100644 --- a/react_class.go +++ b/react_class.go @@ -11,17 +11,21 @@ import ( type Map func(key string) *js.Object // UpdaterFunc is the first argument for SetState function. +// // See: https://reactjs.org/docs/react-component.html#setstate type UpdaterFunc func(props, state Map) interface{} // SetState is used to asynchronously update the state. +// If the new state is dependent on the current props or state, +// updater must be of type UpdaterFunc. +// // See: https://reactjs.org/docs/react-component.html#setstate type SetState func(updater interface{}, callback ...func()) // ForceUpdate will force a rerender of the component. +// // See: https://reactjs.org/docs/react-component.html#forceupdate func ForceUpdate(this *js.Object, callback ...func()) { - if len(callback) > 0 && callback[0] != nil { this.Call("forceUpdate", callback[0]) } else { diff --git a/react_events.go b/react_events.go index 6c115b7..6f4ea63 100644 --- a/react_events.go +++ b/react_events.go @@ -8,6 +8,7 @@ import ( ) // SyntheticEvent represents a SyntheticEvent. +// // See: https://reactjs.org/docs/events.html#overview type SyntheticEvent struct { // O represents the original React SyntheticEvent. @@ -15,48 +16,56 @@ type SyntheticEvent struct { } // Bubbles +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) Bubbles() bool { return s.O.Get("bubbles").Bool() } // Cancelable +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) Cancelable() bool { return s.O.Get("cancelable").Bool() } // CurrentTarget +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) CurrentTarget() dom.HTMLElement { return dom.WrapHTMLElement(s.O.Get("currentTarget")) } // DefaultPrevented +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) DefaultPrevented() bool { return s.O.Get("defaultPrevented").Bool() } // EventPhase +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) EventPhase() int { return s.O.Get("eventPhase").Int() } // IsTrusted +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) IsTrusted() bool { return s.O.Get("isTrusted").Bool() } // NativeEvents +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) NativeEvent() dom.Event { return dom.WrapEvent(s.O.Get("nativeEvent")) } // PreventDefault +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) PreventDefault() { s.O.Call("preventDefault") @@ -69,36 +78,42 @@ func (s *SyntheticEvent) IsDefaultPrevented() bool { } // StopPropagation +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) StopPropagation() { s.O.Call("stopPropagation") } // IsPropagationStopped +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) IsPropagationStopped() bool { return s.O.Call("isPropagationStopped").Bool() } // Target +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) Target() dom.HTMLElement { return dom.WrapHTMLElement(s.O.Get("target")) } // TimeStamp +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) TimeStamp() float64 { return s.O.Get("timeStamp").Float() } // Type +// // See: https://reactjs.org/docs/events.html#overview func (s *SyntheticEvent) Type() string { return s.O.Get("type").String() } // Persist is used if you want to access properties in an asynchronous way. +// // See: https://reactjs.org/docs/events.html#event-pooling func (s *SyntheticEvent) Persist() *SyntheticEvent { p := s.O.Call("persist") diff --git a/react_lifecycle.go b/react_lifecycle.go index 2ba9c5d..4c9757d 100644 --- a/react_lifecycle.go +++ b/react_lifecycle.go @@ -44,6 +44,7 @@ func (def ClassDef) GetInitialState(f func(this *js.Object, props Map) interface } // GetDerivedStateFromProps sets the getDerivedStateFromProps class method. +// // See: https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html func (def ClassDef) GetDerivedStateFromProps(f func(nextProps, prevState Map) interface{}) { @@ -61,6 +62,7 @@ func (def ClassDef) GetDerivedStateFromProps(f func(nextProps, prevState Map) in } // ComponentDidMount sets the componentDidMount method. +// // See: https://reactjs.org/docs/react-component.html#componentdidmount func (def ClassDef) ComponentDidMount(f func(this *js.Object, props, state Map, setState SetState)) { def.SetMethod(componentDidMount, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { @@ -70,6 +72,7 @@ func (def ClassDef) ComponentDidMount(f func(this *js.Object, props, state Map, } // ComponentWillUnmount sets the componentWillUnmount method. +// // See: https://reactjs.org/docs/react-component.html#componentwillunmount func (def ClassDef) ComponentWillUnmount(f func(this *js.Object, props, state Map)) { def.SetMethod(componentWillUnmount, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { @@ -79,6 +82,7 @@ func (def ClassDef) ComponentWillUnmount(f func(this *js.Object, props, state Ma } // ShouldComponentUpdate sets the shouldComponentUpdate method. +// // See: https://reactjs.org/docs/react-component.html#shouldcomponentupdate func (def ClassDef) ShouldComponentUpdate(f func(this *js.Object, props, nextProps, state, nextState Map) bool) { def.SetMethod(shouldComponentUpdate, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { @@ -93,6 +97,7 @@ func (def ClassDef) ShouldComponentUpdate(f func(this *js.Object, props, nextPro } // GetSnapshotBeforeUpdate sets the getSnapshotBeforeUpdate method. +// // See: https://reactjs.org/docs/react-component.html#getsnapshotbeforeupdate func (def ClassDef) GetSnapshotBeforeUpdate(f func(this *js.Object, prevProps, props, prevState, state Map) interface{}) { def.SetMethod(getSnapshotBeforeUpdate, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { @@ -115,6 +120,7 @@ func (def ClassDef) GetSnapshotBeforeUpdate(f func(this *js.Object, prevProps, p } // ComponentDidUpdate sets the componentDidUpdate method. +// // See: https://reactjs.org/docs/react-component.html#componentdidupdate func (def ClassDef) ComponentDidUpdate(f func(this *js.Object, prevProps, props, prevState, state Map, setState SetState, snapshot *js.Object)) { def.SetMethod(componentDidUpdate, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { @@ -131,6 +137,8 @@ func (def ClassDef) ComponentDidUpdate(f func(this *js.Object, prevProps, props, } // Render sets the render method. +// +// See: https://reactjs.org/docs/react-component.html#render func (def ClassDef) Render(f func(this *js.Object, props, state Map) interface{}) { def.SetMethod(render, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { return f(this, props, state) @@ -138,6 +146,8 @@ func (def ClassDef) Render(f func(this *js.Object, props, state Map) interface{} } // ComponentDidCatch sets the componentDidCatch method. +// +// See: https://reactjs.org/docs/react-component.html#componentdidcatch func (def ClassDef) ComponentDidCatch(f func(this *js.Object, err, info *js.Object, props, state Map, setState SetState)) { def.SetMethod(componentDidCatch, func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{} { err := arguments[0] diff --git a/utility_funcs.go b/utility_funcs.go index bb9db87..43218a6 100644 --- a/utility_funcs.go +++ b/utility_funcs.go @@ -8,6 +8,7 @@ import ( // Set is used for conveniently dealing with // data-* and aria-* attributes. +// // See: https://reactjs.org/docs/dom-elements.html type Set map[string]string @@ -26,6 +27,7 @@ func (s Set) Convert(base string) map[string]string { // DangerouslySetInnerHTMLFunc is a convience function used for setting the DOM // object's inner html. The functon takes a function for the argument. +// // See: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml func DangerouslySetInnerHTMLFunc(inside func() interface{}) map[string]interface{} { return map[string]interface{}{ @@ -37,6 +39,7 @@ func DangerouslySetInnerHTMLFunc(inside func() interface{}) map[string]interface // DangerouslySetInnerHTML is a convience function used for setting the DOM // object's inner html. The function takes the inner html content directly. +// // See: https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml func DangerouslySetInnerHTML(inside interface{}) map[string]interface{} { return DangerouslySetInnerHTMLFunc(func() interface{} { return inside })