Components and Hooks for Vue.
Using npm:
$ npm install --save opp-vue
Return registered plugin with react hooks.
type usePlugin = (name: string) => Plugin['hooks'];
import { registerPlugin, start } from 'opp-core';
import { usePlugin } from 'opp-vue';
const plugin = { name: 'test', hooks: {} };
registerPlugin(plugin);
start();
const Component = (props = {}) => {
usePlugin('test') === plugin.hooks;
return <div>Component</div>;
};
PluginRender
will render matched plugin with react lifecycle.
type Props = { id: string };
type PluginRender = ComponentType<Props>;
PluginRender
will do those things:
- Create
HTMLDivElement
withid
same asprops.id
; - Use
props.id
to find plugin with sameplugin.container
; - Run
plugin.mount
with parameters: element (HTMLDivElement
), props (props
omitid
);
PluginRender
will do those things:
- Use
props.id
to find plugin with sameplugin.container
; - Run
plugin.update
with parameters: props (props
omitid
);
PluginRender
will do those things:
- Use
props.id
to find plugin with sameplugin.container
; - Run
plugin.unmount
with no parameters;
Create plugin with React Component.
type CreatePlugin = (Component: ComponentType) => (plugin: Plugin) => Plugin;
import { useState } from 'react';
import { PluginRender, createPlugin } from 'opp-vue';
import { ElInput } from 'element-plus';
const plugin = createPlugin(ElInput)({
name: 'input',
container: 'input-element',
});
registerPlugin(plugin);
start();
const Component = (props = {}) => {
const [value, setValue] = useState('');
return (
<PluginRender id="input-element" value={value} onChange={setValue} />
);
};