Functional Components
CxJS offers functional components, similar to React. Functional components provide a simple way to create structures composed out of several CxJS components.
In the following example, a new functional component is defined and then used to create multiple flavors of the same chart.
<div class="widgets">
<LineChart
chartStyle="width: 300px; height: 200px; background: white;"
lineStyle="stroke: red"
data={Array.from({length: 100}, (_, x) => ({ x, y: 75 - 50 * Math.random() }))}
/>
<LineChart
chartStyle="width: 300px; height: 200px; background: black"
lineStyle="stroke: green; stroke-width: 1"
data={Array.from({length: 100}, (_, x) => ({ x, y: 75 - 50 * Math.random() }))}
/>
<LineChart
chartStyle="width: 300px; height: 200px; background: blue"
lineStyle="stroke: white; stroke-width: 2"
data={Array.from({length: 100}, (_, x) => ({ x, y: 75 - 50 * Math.random() }))}
/>
</div>import {createFunctionalComponent} from 'cx/ui';If functional components contain additional logic, it's required to wrap them inside a createFunctionalComponent call.
Note that React (functional) components can freely be mixed with CxJS, therefore,
createFunctionalComponentis required when a CxJS functional component doesn't have a recognizable syntax.
Reserved property names
A number of properties that can be passed to functional components are important for the internal workings of the Cx framework. They ensure functional components work well
with other Cx widgets, and should not be used within the function body.
| Property | Description | Type |
|---|---|---|
controller | Controller passed to a functional component will automatically be initialized, as with any other component. | controller |
layout | Defines the inner layout that will be applied to child elements. | widget |
outerLayout | Defines the outer layout which wraps the functional component. | widget |
visible | If | boolean |