opencomponents / oc-template-react

⚛️ Module for handling React templates in OC
MIT License
23 stars 16 forks source link
opencomponents react

This package has been moved

Use the new oc-template-react template on vite-templates

oc-template-react

=================

react-templates & utilities for the OpenComponents template system


Module for handling React templates in OC

codecov Known Vulnerabilities npm version

Node8 Node9 Node10
Node8 Node9 Node10

Packages included in this repo

Name Version
oc-template-react npm version
oc-template-react-compiler npm version
oc-react-component-wrapper npm version

Usage:

Initialize a component with the oc-template-react and follow the CLI instructions

$ oc init <your-component-name> oc-template-react

Extra info:

package.json requirements

conventions

externals

Externals are not bundled when packaging and publishing the component, for better size taking advantage of externals caching. OC will make sure to provide them at Server-Side & Client-Side rendering time for you.

features

Utils

The compiler exposes some utilities that could be used by your React application:

HOCs

withDataProvider

An Higher order component that will make a getData function available via props.

Usage:
import { withDataProvider } from 'oc-template-react-compiler/utils';

const yourApp = props => {
  // you can use props.getData here
};

yourEnhancedApp = withDataProvider(yourApp);

getData accept two arguments: (params, callback) => callback(err, result). It will perform a post back request to the component endpoint with the specified query perams invoking the callback with the results.

For more details, check the example app

withSettingProvider

An Higher order component that will make a getSetting function available via props.

Usage:
import { withSettingProvider } from 'oc-template-react-compiler/utils';

const yourApp = props => {
  // you can use props.getSetting here
};

yourEnhancedApp = withSettingProvider(yourApp);

getSetting accept one argument: settingName => settingValue. It will return the value for the requested setting.

Settings available at the moment: