Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-callable
Advanced tools
Callable components, that can be called from anywhere in your application.
Callable components, that can be called from anywhere in your application.
This repository still in work in progress
state.
This repository is not production tested yet.
This repository is not fully described. (Sorry, I will finish it as soon as possible)
Even when there is a very interesting package like react-confirm
, I wanted to reinvent bicycle and create another interpretation of a library, allowing you, me and everybody else to create callable components.
However, the main purpose of that library is to allow the creation of any type of components, i.e. modal dialogs, messages on different sides of a screen, tooltips, popovers and so on. Actually, it does not mean, that react-callable will do all the stuff. It just gives some sort of help.
When imagine what can be done, I made up 5 concepts to be reached.
npm i --save react-callable
or
yarn add react-callable
import { createCallable } from 'react-callable';
Function that accepts an object of settings with following structure:
customRoot
can also be a function, that will be resolved when callable is called.
It should return reference to a DOM element.dynamicRoot
is a special mechanism,
that allows you to pass reference to a target element as the very last argument into a call (at least it should be second arg, take it into account, examples below)import { createCallable } from "react-callable";
const confirmCreator = createCallable({ async: true, arguments: ['title', 'description', 'submitStatus', 'cancelStatus'], callableId: 1 });
const Confirm = ({ title, description, submitStatus, cancelStatus, conclude }) => {
return (
<div className={styles.confirmWrapper}>
<div className={styles.confirmBackdrop} onClick={() => { conclude(cancelStatus); }} />
<div className={styles.confirm}>
<div className="header">
<h1>
{title}
</h1>
</div>
<div className="content">
<p>
{description}
</p>
</div>
<div className="actions">
<div className="btn-group" style={{ float: 'right' }}>
<button className="btn" onClick={() => conclude(submitStatus)}>Submit</button>
<button className="btn" onClick={() => conclude(cancelStatus)}>Cancel</button>
</div>
</div>
</div>
</div>
);
};
const confirm = confirmCreator(Confirm);
export default confirm;
import React, {Component} from 'react';
import confirm from './components/Confirm';
import classNames from './styles.module.scss';
class App extends Component {
openConfirm = () => {
confirm('Hello World', 'Called by React Callable', 'submitted', 'cancelled').then((response) => alert(`confirm is ${response}`));
};
render() {
return (
<div className={classNames.app}>
<button className="btn large" onClick={this.openConfirm}>
Confirm me
</button>
</div>
);
}
}
export default App;
import { createCallable } from "react-callable";
const confirmCreator = createCallable({ async: true, arguments: ['title', 'description', 'onSubmit', 'onCancel'], callableId: 1 });
const Confirm = ({ title, description, onSubmit, onCancel, conclude }) => {
return (
<div className={styles.confirmWrapper}>
<div className={styles.confirmBackdrop} onClick={() => { onCancel(); conclude(); }} />
<div className={styles.confirm}>
<div className="header">
<h1>
{title}
</h1>
</div>
<div className="content">
<p>
{description}
</p>
</div>
<div className="actions">
<div className="btn-group" style={{ float: 'right' }}>
<button className="btn" onClick={() => {onSubmit(); conclude();}}>Submit</button>
<button className="btn" onClick={() => {onCancel(); conclude();}}>Cancel</button>
</div>
</div>
</div>
</div>
);
};
const confirm = confirmCreator(Confirm);
export default confirm;
import React, {Component} from 'react';
import confirm from './components/Confirm';
import classNames from './styles.module.scss';
class App extends Component {
openConfirm = () => {
confirm('Hello World', 'Called by React Callable', () => console.log('Harry'), () => console.log('Volan'));
};
render() {
return (
<div className={classNames.app}>
<button className="btn large" onClick={this.openConfirm}>
Confirm me
</button>
</div>
);
}
}
export default App;
Now I will try to show only main differences. Sorry, but code takes a lot of space.
import { createCallable } from "react-callable";
// create confirm with 4 arguments and enable passing root as very last argument
const confirmCreator = createCallable({
arguments: [
'title',
'description',
'onSubmit',
'onCancel'
],
dynamicRoot: true
});
// assume that Confirm was already defined somewhere
const confirm = confirmCreator(Confirm);
// because we turned on dynamicRoot,
// confirm will look for the very last argument,
// i.e. argument, that is be placed after all arguments,
// described in createCallable function
confirm(
'Are you sure?',
"You're going to do something?",
() => alert('Just do it!'),
() => alert("It's time to stop!"),
document.querySelector('body > .custom-container')
)
To be honest, I made this package for self-usage, but I will be proud, if someone else will find it useful.
FAQs
Callable components, that can be called from anywhere in your application.
The npm package react-callable receives a total of 6 weekly downloads. As such, react-callable popularity was classified as not popular.
We found that react-callable 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.