1.0.13 • Published 11 months ago

@jswork/react-command-manager v1.0.13

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

react-command-manager

React command manager.

installation

yarn add @jswork/react-command-manager

usage

  1. 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>
1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago