1.0.13 • Published 11 months ago
@jswork/react-command-manager v1.0.13
react-command-manager
React command manager.
installation
yarn add @jswork/react-command-manager
usage
- Add provider to root.
import React from 'react'; import ReactDOM from 'react-dom/client'; import { scanVite } from '@jswork/scan-modules'; import ReactCommandManager from '@jswork/react-command-manager/src/main';
const moduleFiles = import.meta.glob('./shared/commands/*/.ts', { eager: true }); const modules = scanVite(moduleFiles, { modules: '/commands/', });
import App from './app'; import './index.scss';
ReactDOM.createRoot(document.getElementById('root')!).render( , );
> 2. define a command
```jsx
import { defineCommand } from '@jswork/react-command-manager';
export default defineCommand({
methods: {
init(){
console.log('init posts will execute at first time');
},
create() {
console.log('create posts');
},
update({ title }) {
console.log('update post', title);
},
},
});
3. execute a command
<button onClick={() => nx.$exec('posts.create')}>Create</button>