Documentation
¶
Index ¶
- Variables
- func AddClass(currentClasses, newClass string) string
- func CloneElement(element interface{}, props interface{}, children ...interface{}) *js.Object
- func CreateClass(def ClassDef) *js.Object
- func CreateContext(defaultValue ...interface{}) (Context *js.Object, Provider *js.Object, Consumer *js.Object)
- func CreateRef() *js.Object
- func DangerouslySetInnerHTML(inside interface{}) map[string]interface{}
- func DangerouslySetInnerHTMLFunc(inside func() interface{}) map[string]interface{}
- func ForceUpdate(this *js.Object, callback ...func())
- func ForwardRef(component interface{}) *js.Object
- func Fragment(key *string, children ...interface{}) *js.Object
- func GetElementByID(id string, dom ...*js.Object) *js.Object
- func HydrateProps(this *js.Object, strct interface{}) errordeprecated
- func HydrateState(this *js.Object, strct interface{}) errordeprecated
- func JSFn(funcName string, args ...interface{}) (_ *js.Object, rErr error)
- func JSONUnmarshal(json string) (*js.Object, error)
- func JSX(component interface{}, props interface{}, children ...interface{}) *js.Object
- func M(kvs ...interface{}) map[string]interface{}deprecated
- func Profiler(id string, onRender OnRenderCallback, children ...interface{}) *js.Object
- func RemoveClass(currentClasses, removeClass string) string
- func Render(element *js.Object, domTarget *js.Object, callback ...func()) *js.Object
- func SToMap(s interface{}) map[string]interface{}
- func UnmarshalProps(this *js.Object, strct interface{}) error
- func UnmarshalState(this *js.Object, strct interface{}) error
- func UnmarshalStruct(mp map[string]interface{}, strct interface{}) error
- type ClassDef
- func (def ClassDef) ComponentDidCatch(...)
- func (def ClassDef) ComponentDidMount(f func(this *js.Object, props, state Map, setState SetState))
- func (def ClassDef) ComponentDidUpdate(...)
- func (def ClassDef) ComponentWillUnmount(f func(this *js.Object, props, state Map))
- func (def ClassDef) GetDefaultProps(f func(this *js.Object) interface{})
- func (def ClassDef) GetDerivedStateFromError(f func(err *js.Object) interface{})
- func (def ClassDef) GetDerivedStateFromProps(f func(props, state Map) interface{})
- func (def ClassDef) GetInitialState(f func(this *js.Object, props Map) interface{})
- func (def ClassDef) GetSnapshotBeforeUpdate(f func(this *js.Object, prevProps, props, prevState, state Map) interface{})
- func (def ClassDef) Render(f func(this *js.Object, props, state Map) interface{})
- func (def ClassDef) SetEventHandler(name string, ...)
- func (def ClassDef) SetMethod(name string, ...)
- func (def ClassDef) SetMultiArgEventHandler(name string, ...)
- func (def ClassDef) SetPropTypes(propTypes interface{})
- func (def ClassDef) ShouldComponentUpdate(f func(this *js.Object, props, nextProps, state, nextState Map) bool)
- type Map
- type OnRenderCallback
- type Set
- type SetState
- type SyntheticEvent
- func (s *SyntheticEvent) Bubbles() bool
- func (s *SyntheticEvent) Cancelable() bool
- func (s *SyntheticEvent) CurrentTarget() *js.Object
- func (s *SyntheticEvent) DefaultPrevented() bool
- func (s *SyntheticEvent) EventPhase() int
- func (s *SyntheticEvent) IsDefaultPrevented() bool
- func (s *SyntheticEvent) IsPropagationStopped() bool
- func (s *SyntheticEvent) IsTrusted() bool
- func (s *SyntheticEvent) NativeEvent() *js.Object
- func (s *SyntheticEvent) Persist() *SyntheticEvent
- func (s *SyntheticEvent) PreventDefault()
- func (s *SyntheticEvent) StopPropagation()
- func (s *SyntheticEvent) Target() *js.Object
- func (s *SyntheticEvent) TimeStamp() float64
- func (s *SyntheticEvent) Type() string
- type UpdaterFunc
Constants ¶
This section is empty.
Variables ¶
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.Get("createReactClass") // PureComponentMixin points to react-addons-pure-render-mixin module. // It is optional, but required if you want to create a PureComponent. // // Example: // // pureDef := react.NewClassDef("Pure", react.PureComponentMixin) // // See: https://www.npmjs.com/package/react-addons-pure-render-mixin PureComponentMixin = js.Global.Get("PureRenderMixin") )
Functions ¶
func CloneElement ¶
CloneElement is used to clone and return a new React Element.
func CreateClass ¶
CreateClass is used to create a react component.
func CreateContext ¶
func CreateContext(defaultValue ...interface{}) (Context *js.Object, Provider *js.Object, Consumer *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 DangerouslySetInnerHTML ¶
func DangerouslySetInnerHTML(inside 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 DangerouslySetInnerHTMLFunc ¶
func DangerouslySetInnerHTMLFunc(inside func() interface{}) map[string]interface{}
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 ForceUpdate ¶
ForceUpdate will force a rerender of the component.
See: https://reactjs.org/docs/react-component.html#forceupdate
func ForwardRef ¶
ForwardRef will forward a Ref to child components.
func GetElementByID ¶
GetElementByID will return the first element with the specified id in the dom object. If no dom is provided, window.document will be used.
func HydrateProps
deprecated
func HydrateState
deprecated
func JSFn ¶
JSFn is a convenience function used to call javascript native functions. If the native function throws an exception, then a *js.Error is returned.
Example:
// alert('Hello World!') JSFn("alert", "Hello World!") // JSON.parse('{"name":"John"}') JSFn("JSON.parse", `{"name":"John"}`)
func JSONUnmarshal ¶
JSONUnmarshal provides a simple way to unmarshal json encoded strings to structs.
See: https://github.com/gopherjs/gopherjs/wiki/Using-native-JSON-parsing-to-realize-a-slim-JSON-decoder for a tutorial with an example.
func M
deprecated
func M(kvs ...interface{}) map[string]interface{}
M is shorthand for map[string]interface{}.
Example:
react.M("className", "preview", "escapeHtml", false) js.M{"className": "preview", "escapeHtml": false} // Instead of map[string]interface{}{"className": "preview", "escapeHtml": false}
Deprecated: Use js.M instead (for type safety, linting and formatting).
func Profiler ¶
func Profiler(id string, onRender OnRenderCallback, children ...interface{}) *js.Object
Profiler is used to find performance bottlenecks in your application.
func RemoveClass ¶
RemoveClass removes a class from an existing list of classes.
func SToMap ¶
func SToMap(s interface{}) map[string]interface{}
SToMap will convert a struct or pass-through a map. If the argument is a struct, it will convert it to a map. If the argument is a map, it will pass it through. If the argument is nil, it will return nil.
func UnmarshalProps ¶
UnmarshalProps will unmarshal a given struct with values from the component's prop. strct must be a pointer to a struct.
func UnmarshalState ¶
UnmarshalState will unmarshal a given struct with values from the component's state. strct must be a pointer to a struct.
func UnmarshalStruct ¶
UnmarshalStruct will unmarshal a struct with values from a map. strct must be a pointer to a struct. Use struct tag "react" for linking map keys to the struct's fields.
Types ¶
type ClassDef ¶
type ClassDef map[string]interface{}
ClassDef is used to create custom React components.
func NewClassDef ¶
NewClassDef will create an empty class definition which can immediately be used to create a React component. displayName is the text that is shown in Chrome's React Developer Tools.
Example:
// Create PureComponent pureDef := react.NewClassDef("Pure", react.PureComponentMixin) // Create Component appDef := react.NewClassDef("App")
See: https://reactjs.org/docs/react-api.html#reactpurecomponent and https://reactjs.org/docs/react-component.html
func (ClassDef) ComponentDidCatch ¶
func (def ClassDef) ComponentDidCatch(f func(this *js.Object, err, info *js.Object, props, state Map, setState SetState))
ComponentDidCatch sets the componentDidCatch method.
See: https://reactjs.org/docs/react-component.html#componentdidcatch
func (ClassDef) ComponentDidMount ¶
ComponentDidMount sets the componentDidMount method.
See: https://reactjs.org/docs/react-component.html#componentdidmount
func (ClassDef) ComponentDidUpdate ¶
func (def ClassDef) ComponentDidUpdate(f func(this *js.Object, prevProps, props, prevState, state Map, setState SetState, snapshot *js.Object))
ComponentDidUpdate sets the componentDidUpdate method.
See: https://reactjs.org/docs/react-component.html#componentdidupdate
func (ClassDef) ComponentWillUnmount ¶
ComponentWillUnmount sets the componentWillUnmount method.
See: https://reactjs.org/docs/react-component.html#componentwillunmount
func (ClassDef) GetDefaultProps ¶
GetDefaultProps sets the getDefaultProps method.
See: https://reactjs.org/docs/react-without-es6.html#declaring-default-props
func (ClassDef) GetDerivedStateFromError ¶
GetDerivedStateFromError sets the getDerivedStateFromError class method.
See: https://reactjs.org/docs/react-component.html#static-getderivedstatefromerror
func (ClassDef) GetDerivedStateFromProps ¶
GetDerivedStateFromProps sets the getDerivedStateFromProps class method.
See: https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html
func (ClassDef) GetInitialState ¶
GetInitialState sets the getInitialState method. Note: It is usually not recommended to use the props when setting the initial state.
func (ClassDef) GetSnapshotBeforeUpdate ¶
func (def ClassDef) GetSnapshotBeforeUpdate(f func(this *js.Object, prevProps, props, prevState, state Map) interface{})
GetSnapshotBeforeUpdate sets the getSnapshotBeforeUpdate method.
See: https://reactjs.org/docs/react-component.html#getsnapshotbeforeupdate
func (ClassDef) SetEventHandler ¶
func (def ClassDef) SetEventHandler(name string, f func(this *js.Object, e *SyntheticEvent, props, state Map, setState SetState))
SetEventHandler allows a custom event handler to be attached. By passing nil for f, the handler can also be detached (cleared).
It can be used like this: "onClick": this.Get("clickhandler")
func (ClassDef) SetMethod ¶
func (def ClassDef) SetMethod(name string, f func(this *js.Object, props, state Map, setState SetState, arguments []*js.Object) interface{})
SetMethod allows a custom method to be attached. By passing nil for f, the method can also be detached (cleared).
func (ClassDef) SetMultiArgEventHandler ¶
func (def ClassDef) SetMultiArgEventHandler(name string, f func(this *js.Object, arguments []*js.Object) func(this *js.Object, e *SyntheticEvent, props, state Map, setState SetState))
SetMultiArgEventHandler allows for you to pass custom arguments to a custom event handler. By passing nil for f, the handler can also be detached (cleared).
It can be used like this: "onClick": this.Get("clickhandler").Invoke(5)
See: https://reactjs.org/docs/handling-events.html#passing-arguments-to-event-handlers
func (ClassDef) SetPropTypes ¶
func (def ClassDef) SetPropTypes(propTypes interface{})
SetPropTypes is used to typecheck and validate props.
See: https://reactjs.org/docs/typechecking-with-proptypes.html
func (ClassDef) ShouldComponentUpdate ¶
func (def ClassDef) ShouldComponentUpdate(f func(this *js.Object, props, nextProps, state, nextState Map) bool)
ShouldComponentUpdate sets the shouldComponentUpdate method.
See: https://reactjs.org/docs/react-component.html#shouldcomponentupdate
type OnRenderCallback ¶
type OnRenderCallback func(id string, phase string, actualDuration, baseDuration float64, startTime, commitTime float64, interactions *js.Object)
OnRenderCallback is the callback function signature of the onRender argument to Profiler function.
type SetState ¶
type SetState func(updater interface{}, callback ...func())
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.
type SyntheticEvent ¶
SyntheticEvent represents a SyntheticEvent.
See: https://reactjs.org/docs/events.html#overview
func (*SyntheticEvent) CurrentTarget ¶
func (s *SyntheticEvent) CurrentTarget() *js.Object
CurrentTarget ...
See: https://reactjs.org/docs/events.html#overview
Example:
import "honnef.co/go/js/dom" dom.WrapHTMLElement(e.CurrentTarget())
func (*SyntheticEvent) DefaultPrevented ¶
func (s *SyntheticEvent) DefaultPrevented() bool
DefaultPrevented ...
func (*SyntheticEvent) IsDefaultPrevented ¶
func (s *SyntheticEvent) IsDefaultPrevented() bool
IsDefaultPrevented ... See: https://reactjs.org/docs/events.html#overview
func (*SyntheticEvent) IsPropagationStopped ¶
func (s *SyntheticEvent) IsPropagationStopped() bool
IsPropagationStopped ...
func (*SyntheticEvent) NativeEvent ¶
func (s *SyntheticEvent) NativeEvent() *js.Object
NativeEvent ...
See: https://reactjs.org/docs/events.html#overview
Example:
import "honnef.co/go/js/dom" dom.WrapEvent(e.NativeEvent())
func (*SyntheticEvent) Persist ¶
func (s *SyntheticEvent) Persist() *SyntheticEvent
Persist is used if you want to access properties in an asynchronous way.
func (*SyntheticEvent) PreventDefault ¶
func (s *SyntheticEvent) PreventDefault()
PreventDefault ...
func (*SyntheticEvent) StopPropagation ¶
func (s *SyntheticEvent) StopPropagation()
StopPropagation ...
func (*SyntheticEvent) Target ¶
func (s *SyntheticEvent) Target() *js.Object
Target ...
See: https://reactjs.org/docs/events.html#overview
Example:
import "honnef.co/go/js/dom" dom.WrapHTMLElement(e.Target())
type UpdaterFunc ¶
type UpdaterFunc func(props, state Map) interface{}
UpdaterFunc is the first argument for SetState function.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
forks
|
|
encoding/json
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
|
Package json implements encoding and decoding of JSON objects as defined in RFC 4627. |
mapstructure
Package mapstructure exposes functionality to convert an arbitrary map[string]interface{} into a native Go structure.
|
Package mapstructure exposes functionality to convert an arbitrary map[string]interface{} into a native Go structure. |