BaseWidget class

The base component that provides basic functionality to create a widget.

Extends

Component<P, S & BaseWidgetState>

Constructors

BaseWidget<P, S>(Readonly<P>)

Constructor of BaseWidget.

Inherited Properties

context

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType. Should be used with type annotation or static contextType.

Example

static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>

See React Docs

contextType

If set, this.context will be set at runtime to the current value of the given Context.

Example

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
  static contextType = Ctx
  context!: React.ContextType<typeof Ctx>
  render () {
    return <>My context's value: {this.context}</>;
  }
}

See https://react.dev/reference/react/Component#static-contexttype

props
refs

See Legacy React Docs

state

Methods

body()

The purpose of this method is to provide a way for you to add custom body content to the widget. By overriding this method, you can add additional functionality or styling to the widget's body. If the method is not overridden, the widget will return undefined as the default value for the body, indicating that no custom body content has been defined.

componentDidMount()

Called after the component is mounted. You can do initialization that requires DOM nodes here. You can also make network requests here if you need to load data from a remote endpoint.

footer()

The purpose of this method is to provide a way for you to add custom footer content to the widget. By overriding this method, you can add additional functionality or styling to the widget's footer. If the method is not overridden, the widget will return undefined as the default value for the footer, indicating that no custom footer content has been defined.

getData()

Get data required by the widget

header()

The purpose of this method is to provide a way for you to add custom header content to the widget. By overriding this method, you can add additional functionality or styling to the widget's header. If the method is not overridden, the widget will return undefined as the default value for the header, indicating that no custom header content has been defined.

loading()

This method is typically called when the widget is in the process of fetching data. The undefined return value is used to indicate that no loading indicator is required. If a loading indicator is required, the method can return a JSX.Element containing the necessary components to render the loading indicator.

render()

Defines the default layout for the widget.

styling()

Override this method to returns an object that defines the class names for the different parts of the widget. The returned object conforms to the IWidgetClassNames interface which defines the possible keys and values for the class names.

Inherited Methods

componentDidCatch(Error, ErrorInfo)

Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

componentDidUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Called immediately after updating occurs. Not called for the initial render.

The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.

componentWillMount()

Called immediately before mounting occurs, and before <xref:Component.render>. Avoid introducing any side-effects or subscriptions in this method.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

componentWillReceiveProps(Readonly<P>, any)

Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.

Calling <xref:Component.setState> generally does not trigger this method.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

componentWillUnmount()

Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

componentWillUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Called immediately before rendering when new props or state is received. Not called for the initial render.

Note: You cannot call <xref:Component.setState> here.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

forceUpdate(() => void)
getSnapshotBeforeUpdate(Readonly<P>, Readonly<S & BaseWidgetState>)

Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

Note: the presence of this method prevents any of the deprecated lifecycle events from running.

setState<K>(null | (S & BaseWidgetState) | (prevState: Readonly<S & BaseWidgetState>, props: Readonly<P>) => null | (S & BaseWidgetState) | Pick<S & BaseWidgetState, K> | Pick<S & BaseWidgetState, K>, () => void)
shouldComponentUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Called to determine whether the change in props and state should trigger a re-render.

Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

If false is returned, <xref:Component.render>, componentWillUpdate and componentDidUpdate will not be called.

UNSAFE_componentWillMount()

Called immediately before mounting occurs, and before <xref:Component.render>. Avoid introducing any side-effects or subscriptions in this method.

This method will not stop working in React 17.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

UNSAFE_componentWillReceiveProps(Readonly<P>, any)

Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.

Calling <xref:Component.setState> generally does not trigger this method.

This method will not stop working in React 17.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

UNSAFE_componentWillUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Called immediately before rendering when new props or state is received. Not called for the initial render.

Note: You cannot call <xref:Component.setState> here.

This method will not stop working in React 17.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

Constructor Details

BaseWidget<P, S>(Readonly<P>)

Constructor of BaseWidget.

new BaseWidget(props: Readonly<P>)

Parameters

props

Readonly<P>

The props of the component.

Inherited Property Details

context

If using the new style context, re-declare this in your class to be the React.ContextType of your static contextType. Should be used with type annotation or static contextType.

Example

static contextType = MyContext
// For TS pre-3.7:
context!: React.ContextType<typeof MyContext>
// For TS 3.7 and above:
declare context: React.ContextType<typeof MyContext>

See React Docs

context: unknown

Property Value

unknown

Inherited From Component.context

contextType

If set, this.context will be set at runtime to the current value of the given Context.

Example

type MyContext = number
const Ctx = React.createContext<MyContext>(0)

class Foo extends React.Component {
  static contextType = Ctx
  context!: React.ContextType<typeof Ctx>
  render () {
    return <>My context's value: {this.context}</>;
  }
}

See https://react.dev/reference/react/Component#static-contexttype

static contextType?: Context<any>

Property Value

Context<any>

Inherited From Component.contextType

props

props: Readonly<P>

Property Value

Readonly<P>

Inherited From Component.props

refs

Warning

This API is now deprecated.

See Legacy React Docs

refs: {[key: string]: ReactInstance}

Property Value

{[key: string]: ReactInstance}

Inherited From Component.refs

state

state: Readonly<S & BaseWidgetState>

Property Value

Readonly<S & BaseWidgetState>

Inherited From Component.state

Method Details

body()

The purpose of this method is to provide a way for you to add custom body content to the widget. By overriding this method, you can add additional functionality or styling to the widget's body. If the method is not overridden, the widget will return undefined as the default value for the body, indicating that no custom body content has been defined.

function body(): undefined | Element

Returns

undefined | Element

An optional JSX.Element representing the body of the widget.

componentDidMount()

Called after the component is mounted. You can do initialization that requires DOM nodes here. You can also make network requests here if you need to load data from a remote endpoint.

function componentDidMount(): Promise<void>

Returns

Promise<void>

The purpose of this method is to provide a way for you to add custom footer content to the widget. By overriding this method, you can add additional functionality or styling to the widget's footer. If the method is not overridden, the widget will return undefined as the default value for the footer, indicating that no custom footer content has been defined.

function footer(): undefined | Element

Returns

undefined | Element

An optional JSX.Element representing the footer of the widget.

getData()

Get data required by the widget

function getData(): Promise<S>

Returns

Promise<S>

Data for the widget

header()

The purpose of this method is to provide a way for you to add custom header content to the widget. By overriding this method, you can add additional functionality or styling to the widget's header. If the method is not overridden, the widget will return undefined as the default value for the header, indicating that no custom header content has been defined.

function header(): undefined | Element

Returns

undefined | Element

An optional JSX.Element representing the header of the widget.

loading()

This method is typically called when the widget is in the process of fetching data. The undefined return value is used to indicate that no loading indicator is required. If a loading indicator is required, the method can return a JSX.Element containing the necessary components to render the loading indicator.

function loading(): undefined | Element

Returns

undefined | Element

A JSX element or undefined if no loading indicator is required.

render()

Defines the default layout for the widget.

function render(): Element

Returns

Element

styling()

Override this method to returns an object that defines the class names for the different parts of the widget. The returned object conforms to the IWidgetClassNames interface which defines the possible keys and values for the class names.

function styling(): IWidgetClassNames

Returns

An object that defines the class names for the different parts of the widget.

Inherited Method Details

componentDidCatch(Error, ErrorInfo)

Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

function componentDidCatch(error: Error, errorInfo: ErrorInfo)

Parameters

error

Error

errorInfo

ErrorInfo

Inherited From Component.componentDidCatch

componentDidUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Called immediately after updating occurs. Not called for the initial render.

The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.

function componentDidUpdate(prevProps: Readonly<P>, prevState: Readonly<S & BaseWidgetState>, snapshot?: any)

Parameters

prevProps

Readonly<P>

prevState

Readonly<S & BaseWidgetState>

snapshot

any

Inherited From Component.componentDidUpdate

componentWillMount()

Warning

This API is now deprecated.

16.3, use componentDidMount or the constructor instead; will stop working in React 17

Called immediately before mounting occurs, and before <xref:Component.render>. Avoid introducing any side-effects or subscriptions in this method.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

function componentWillMount()

Inherited From Component.componentWillMount

componentWillReceiveProps(Readonly<P>, any)

Warning

This API is now deprecated.

16.3, use static getDerivedStateFromProps instead; will stop working in React 17

Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.

Calling <xref:Component.setState> generally does not trigger this method.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

function componentWillReceiveProps(nextProps: Readonly<P>, nextContext: any)

Parameters

nextProps

Readonly<P>

nextContext

any

Inherited From Component.componentWillReceiveProps

componentWillUnmount()

Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

function componentWillUnmount()

Inherited From Component.componentWillUnmount

componentWillUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Warning

This API is now deprecated.

16.3, use getSnapshotBeforeUpdate instead; will stop working in React 17

Called immediately before rendering when new props or state is received. Not called for the initial render.

Note: You cannot call <xref:Component.setState> here.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

function componentWillUpdate(nextProps: Readonly<P>, nextState: Readonly<S & BaseWidgetState>, nextContext: any)

Parameters

nextProps

Readonly<P>

nextState

Readonly<S & BaseWidgetState>

nextContext

any

Inherited From Component.componentWillUpdate

forceUpdate(() => void)

function forceUpdate(callback?: () => void)

Parameters

callback

() => void

Inherited From Component.forceUpdate

getSnapshotBeforeUpdate(Readonly<P>, Readonly<S & BaseWidgetState>)

Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

Note: the presence of this method prevents any of the deprecated lifecycle events from running.

function getSnapshotBeforeUpdate(prevProps: Readonly<P>, prevState: Readonly<S & BaseWidgetState>): any

Parameters

prevProps

Readonly<P>

prevState

Readonly<S & BaseWidgetState>

Returns

any

Inherited From Component.getSnapshotBeforeUpdate

setState<K>(null | (S & BaseWidgetState) | (prevState: Readonly<S & BaseWidgetState>, props: Readonly<P>) => null | (S & BaseWidgetState) | Pick<S & BaseWidgetState, K> | Pick<S & BaseWidgetState, K>, () => void)

function setState<K>(state: null | (S & BaseWidgetState) | (prevState: Readonly<S & BaseWidgetState>, props: Readonly<P>) => null | (S & BaseWidgetState) | Pick<S & BaseWidgetState, K> | Pick<S & BaseWidgetState, K>, callback?: () => void)

Parameters

state

null | (S & BaseWidgetState) | (prevState: Readonly<S & BaseWidgetState>, props: Readonly<P>) => null | (S & BaseWidgetState) | Pick<S & BaseWidgetState, K> | Pick<S & BaseWidgetState, K>

callback

() => void

Inherited From Component.setState

shouldComponentUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Called to determine whether the change in props and state should trigger a re-render.

Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

If false is returned, <xref:Component.render>, componentWillUpdate and componentDidUpdate will not be called.

function shouldComponentUpdate(nextProps: Readonly<P>, nextState: Readonly<S & BaseWidgetState>, nextContext: any): boolean

Parameters

nextProps

Readonly<P>

nextState

Readonly<S & BaseWidgetState>

nextContext

any

Returns

boolean

Inherited From Component.shouldComponentUpdate

UNSAFE_componentWillMount()

Warning

This API is now deprecated.

16.3, use componentDidMount or the constructor instead

Called immediately before mounting occurs, and before <xref:Component.render>. Avoid introducing any side-effects or subscriptions in this method.

This method will not stop working in React 17.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#initializing-state See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

function UNSAFE_componentWillMount()

Inherited From Component.UNSAFE_componentWillMount

UNSAFE_componentWillReceiveProps(Readonly<P>, any)

Warning

This API is now deprecated.

16.3, use static getDerivedStateFromProps instead

Called when the component may be receiving new props. React may call this even if props have not changed, so be sure to compare new and existing props if you only want to handle changes.

Calling <xref:Component.setState> generally does not trigger this method.

This method will not stop working in React 17.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

function UNSAFE_componentWillReceiveProps(nextProps: Readonly<P>, nextContext: any)

Parameters

nextProps

Readonly<P>

nextContext

any

Inherited From Component.UNSAFE_componentWillReceiveProps

UNSAFE_componentWillUpdate(Readonly<P>, Readonly<S & BaseWidgetState>, any)

Warning

This API is now deprecated.

16.3, use getSnapshotBeforeUpdate instead

Called immediately before rendering when new props or state is received. Not called for the initial render.

Note: You cannot call <xref:Component.setState> here.

This method will not stop working in React 17.

Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked.

See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#reading-dom-properties-before-an-update See https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html#gradual-migration-path

function UNSAFE_componentWillUpdate(nextProps: Readonly<P>, nextState: Readonly<S & BaseWidgetState>, nextContext: any)

Parameters

nextProps

Readonly<P>

nextState

Readonly<S & BaseWidgetState>

nextContext

any

Inherited From Component.UNSAFE_componentWillUpdate