withWidgetContext()

Higher-order component which spreads the surrounding WidgetContext's value to the 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>

And somewhere deep down your React component tree:

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

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

export default withWidgetContext(HomeLink);