4.0.2 • Published 4 months ago

oc-template-react v4.0.2

Weekly downloads
73
License
MIT
Repository
github
Last release
4 months ago

oc-template-react

react-templates & utilties for the OpenComponents template system


Module for handling React templates in OC

codecov Known Vulnerabilities npm version

Node8Node9Node10
Node8Node9Node10

Packages included in this repo

NameVersion
oc-template-reactnpm version
oc-template-react-compilernpm version
oc-react-component-wrappernpm 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

  • template.src - the react App entry point - should export a react component as default
  • template.type - oc-template-react
  • required in devDependencies - oc-template-react-compiler

conventions

  • props = server() - the viewModel generated by the server is automatically passed to the react application as props
  • The oc-client-browser is extended and will now expose all the available react-component at oc.reactComponents[bundleHash]
  • You can register an event handler within the oc.events system for the the oc:componentDidMount event. The event will be fired immediately after the react app is mounted.
  • You can register an event handler within the oc.events system for the the oc:cssDidMount event. The event will be fired immediately after the style tag will be added to the active DOM tree.

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.

  • React
  • ReactDOM
  • PropTypes

features

  • Server Side Rendering = server side rendering should work as for any other OpenComponent
  • css-modules are supported.
  • post-css is supported with the following plugins:
  • White list dependencies to be inlcuded in the build process done by the compiler. To whitelist dependencies installed in the node_modules folder, add in the package.json of the component a buildIncludes list:
      ...
      oc : {
        files: {
          template: {
            ...
            buildIncludes: ['react-components-to-build']
          }
        }
      }

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:

  • getSetting('name') : return the name of the OC component
  • getSetting('version') : return the version of the OC component
  • getSetting('baseUrl') : return the baseUrl of the oc-registry
  • getSetting('staticPath') : return the path to the static assets of the OC component
4.0.2

4 months ago

4.0.1

4 months ago

4.0.0

4 months ago

3.0.1

4 months ago

3.0.0-beta.1

4 months ago

3.0.0-beta.0

4 months ago

3.0.0-beta.2

4 months ago

2.1.0

5 years ago

2.0.17

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago