Reference
Nodes
Components
React

React Component

React Components are a powerful new way to add custom functionality to your web apps using the power of React (opens in a new tab).

Define a custom React render function using JSX and pass in its props. Dynaboard and React will take care of the rest. You are able to access any values within the WebAssembly programmatically (e.g. input1.value).

The following React Hooks are supported:

  • useState
  • useCallback
  • useRef
  • useEffect
  • useLayoutEffect

Examples

Hello World

This example will display the text "Hello, World!", and allow the user to override their name using the name prop:

return function HelloWorld({ name = 'World!' }) {
  return <em>Hello, {name}!</em>
}

Counter

This example will display a counter with a button that when clicked, increments the counter:

return function Counter() {
  const [count, setCount] = useState(0)
 
  const incr = useCallback(() => {
    setCount(count + 1)
  }, [count])
 
  const btnStyle = {
    display: 'block',
    background: '#6967E2',
    borderRadius: '6px',
    padding: '4px 8px',
    marginBottom: '8px',
    fontWeight: 600,
  }
 
  return (
    <div>
      <button style={btnStyle} onClick={incr}>
        Click me
      </button>
      <strong>Count:</strong> {count}
    </div>
  )
}

Properties

Visible

PropisVisible
Typeboolean
Defaulttrue

Whether or not this node is visible.

Enabled

PropisEnabled
Typeboolean
Defaulttrue

Whether or not this node is enabled.

Tooltip

Proptooltip
Typestring
Defaultundefined

The tooltip text to display when hovered or focused over this node.

Top

Proptop
Typenumber
Default1

The position of the node from the top side of the grid (grid-row-start).

Left

Propleft
Typenumber
Default1

The position of the node from the left side of the grid (grid-column-start).

Width

Propwidth
Typestring
Default128px

The width of the node. When this node is in a grid layout, this should be done using unitless grid column units (specifying 4 will become grid-column-end: span 4). When this node is in a stack layout, the width can be specified using CSS units (e.g. 100px or 100%), or be left unitless to be treated as flex-grow for the node.

Min Width

PropminWidth
Typestring
Defaultundefined

The minimum width of the node. When this node is in a grid layout, this property is ignored.

Max Width

PropmaxWidth
Typestring
Defaultundefined

The maximum width of the node. When this node is in a grid layout, this property is ignored.

Height

Propheight
Typestring
Default64px

The height of the node. When this node is in a grid layout, this should be done using unitless grid row units (specifying 4 will become grid-row-end: span 4). When this node is in a stack layout, the height can be specified using CSS units (e.g. 100px or 100%), or be left unitless to be treated as flex-grow for the node.

Min Height

PropminHeight
Typestring
Defaultundefined

The minimum height of the node. When this node is in a grid layout, this property is ignored.

Max Height

PropmaxHeight
Typestring
Defaultundefined

The minimum height of the node. When this node is in a grid layout, this property is ignored.

Overflow

Propoverflow
TypeOverflow ('auto' | 'visible' | 'hidden' | 'scroll')
Defaultauto

The strategy used to handle overflow in the horizontal and vertical axes for content that is larger than its container.

Overflow X

PropoverflowX
TypeOverflow ('auto' | 'visible' | 'hidden' | 'scroll')
Defaultauto

The strategy used to handle overflow in the horizontal axis for content that is larger than its container.

Overflow Y

PropoverflowY
TypeOverflow ('auto' | 'visible' | 'hidden' | 'scroll')
Defaultauto

The strategy used to handle overflow in the vertical axis for content that is larger than its container.

Custom Styles

Propstyles
Typestring
Default::component { }

Custom CSS styles to be applied to the node. Use element.styles to refer to the current node.

Object Fit

PropobjectFit
TypeObjectFit ('none' | 'contain' | 'cover' | 'fill' | 'scale-down')
Defaultcover

The strategy used to set how the content of a replaced element should be resized to fit its container.

Props

Propprops
Typeunknown
Default{}

The props to pass into the React component. Must be an object.

Component Source

PropcomponentSource
Typestring
Defaultreturn function Counter() { const [count, setCount] = useState(0) const incr = useCallback(() => { setCount(count + 1) }, [count]) const btnStyle = { display: 'block', background: '#6967E2', borderRadius: '6px', padding: '4px 8px', marginBottom: '8px', fontWeight: 600, } return ( <div> <button style={btnStyle} onClick={incr} > Click me </button> <strong> Count: </strong> {count} </div> ) }

The TypeScript source code for the React component to render. The component function should be returned explicitly using return. JSX and React Hooks are already available in scope.

Event Handlers

On Hover

HandlerinlineReactNode.onHover

Called when the user hovers on the node. Use this event to trigger downstream actions when this node is hovered.

On Leave

HandlerinlineReactNode.onLeave

Called when the user is not hovering over the node. Use this event to trigger downstream actions when this node is no longer hovered.