withWidgetContext()

High order component - HOC - which spreads the surrounding WidgetContext's value to passed component.

Import

import { withWidgetContext } from 'react-union';

or

var withWidgetContext = require('react-union').withWidgetContext;

Input properties

namespace : string

Namespace of the widget. See widget descriptor.

data : object

Data passed by the both widget and common data descriptors.

Example

<div id="navigation"></div>

<!-- Widget descriptor -->
<script
	data-union-widget="navigation"
	type="application/json"
>
	{
		"urls": {
			"home": "www.example.com",
			"api": "/api"
		}
	}
</script>

Than inside your Navigation widget you can use component e.g. like in following code:

import React from 'react';
import { withWidgetContext } from 'react-union';

const HomeLink = ({ data: { urls } }) => (
	<a href={urls.home}>Home</a>
);

export default withWidgetContext(HomeLink);