little-component
v1.0.3
Published
A React component for imperative communication between components, enabling parent-child and sibling function calls without props drilling.
Maintainers
Readme
Little Component
A small React component to access inner functions or variables of React components from outside.
Installation
npm install little-componentUsage
import { LittleComponent, executeFunction, waitAndExecuteFunction } from 'little-component';
function MyComponent() {
const myFunction = () => {
console.log('Hello from inside the component!');
return 'result';
};
return (
<LittleComponent id="myComponent" myFunction={myFunction} />
);
}
// Later, execute the function from outside
executeFunction('myComponent', 'myFunction'); // Logs 'Hello...' and returns 'result'
// Or wait for it to be available
waitAndExecuteFunction('myComponent', 100, 5000, 'myFunction', []);Props
id(string): The component id- Other props are stored in
ref.customData
API
executeFunction(id, functionName, functionParams): Execute a function stored in the component's customDatawaitAndExecuteFunction(id, interval, timeout, functionName, functionParams): Wait for the function to be available and then execute it
Example
The usage example can be found in the example directory.
License
MIT
