
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-entangle
Advanced tools
HOC enabling components to communicate without any shared contexts using native BroadcastChannel API
HOC allowing components to communicate without any shared contexts using native BroadcastChannel API
I found the native API amusing and wondered why has not anyone implemented an HOC in react for this.
Here is a draft implementation in react. I am not sure where or how this API should be used in the react ecosystem,
please enlighten me if you find any meaning ful implementation.
https://aakashrajur.github.io/react-entangle/
npm install --save react-entangle
App.js
import React, { Component, Fragment } from 'react';
import BroadcastHOC from 'react-entangle';
import ComponentA from './ComponentA';
import ComponentB from './ComponentB';
import ComponentC from './ComponentC';
import OtherComponent './OtherComponent';
class App extends Component {
render () {
return (
<BroadcastHOC>
{({data, emitter}) =>
<Fragment>
<ComponentA message={data}/>
<ComponentB emitter={emitter}/>
<ComponentC emitter={emitter} data={data}/>
<OtherComponent/>
</Fragment>}
</BroadcastHOC>
);
}
}
ComponentC.js
import React, { Component } from 'react';
class ComponentC extends Component {
constructor(props){
super(props);
this.onClick = this.onClick.bind(this);
}
render() {
let {data} = this.props;
return(
<div className='wrapper'>
<div>{data ? JSON.stringify(data): 'No data'}</div>
<div><button onClick={this.onClick}>Send Message</button></div>
</div>
);
}
onClick() {
this.props.emitter('channel_name', {hello: 'world', any:'complex data'});
}
}
provide channels on which the HOC will listen and emit data to
type: string or array of strings
you need to provide a function as a child which will receive data and emitter as arguments
({emitter, data}) => <YourComponent emitter={emitter} data={data}/>
Objects emitted are clones and not references.
Functions and errors cannot be sent over
Further Reading
Feel free to use the source anyhow you want.
FAQs
HOC enabling components to communicate without any shared contexts using native BroadcastChannel API
We found that react-entangle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.