BaseComponent

A Higher Order Component (HOC) that transforms any HTML tag or React component into a pure JavaScript function. You can import your components created on React and React Native and use them in oneJS through this HOC. You can check the docs for the standard components created using BaseComponent.

Function Input

Name

Type

Mandatory

Description

Default

name

String

Yes

Unique name for the component.

hasChildren

Boolean

Yes

Specifies whether the component accepts a nested component. E.g.: This property is true for View components and false for Input components.

ComponentFunctionOrTag

String or Component

Yes

It can be provided in two ways:

  • Tag name: The HTML tag name to be transformed into a JavaScript function. Web only.
  • Component: The React or React Native component to be transformed into a JavaScript function.

Function Output

Type

Description

Component

The component function created.

Example

import {app, BaseComponent, readFlavor} from '@onejs-dev/core';
import {View, Text, Input} from '@onejs-dev/components';

const H1Html = BaseComponent('H1Html', true, 'h1');
const InputHtml = BaseComponent('InputHtml', false, 'input');

const App = () => View({content: {direction: 'column', h: 'center', v: 'center', gap: 10}, self: {expand: 1}})([
H1Html({id: 'myH1'})('Standard H1'),
InputHtml({type: 'range', value: 5, min: 1, max: 10})
]);

app({component: App, theme: {preset: 'oneJS'}});