Skip to content

cid-chen/react-mvvm-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React 17‑19 Support bundlephobia License

react-mvvm-component v1.2.0

React is an awesome library. "React MVVM Component" make its state management better.

Frustrated with complex local state flow or debugging hooks and effects in components?

React MVVM Component = React Function Component + MVVM Options API

Using this new hook plugin, you can manage "in-component state" more clearly and intuitively.

Lightweight 6KB, supports React 17–19 and the essence of Function Components remains unchanged.

Seamlessly compatible with native components, existing projects and React ecosystem !

Live Demo

Live Demo (zh-TW)

MVVM component is still a React function component !

MVVM component is not intended to replace existing tools, but rather to extend their functionality with a complementary architectural pattern that may be more suitable in certain scenarios.

Therefore, the MVVM component is still a function component, so you can use it directly in your existing project.

It works seamlessly with other function components, please refer to demo: Entitly, Parent-Child, and Example8_1's original syntax for more information.

Installation

npm install @gratefuljs/react-mvvm-component

or

pnpm install @gratefuljs/react-mvvm-component

Basic Example

Built on React, this plugin is easy to set up — just plug it into your project and enjoy the extended functionality:

import ReactDOM from 'react-dom/client';
import React from 'react';
import { useRespectVue } from '@gratefuljs/react-mvvm-component';
 
const App = ()=>{ // The MVVM component is still a React function component
  
  const [MVVMComponent, VMmethodsAPI] = useRespectVue(React, {
    view : ({$VM, methods, refDOM}) => (
      <div>
        <p>Count: { $VM('count') }</p>
 
        <button onClick={methods.plus}>+</button>
        &nbsp;
        <button onClick={methods.minus}>-</button>
      </div>),
    methods : ({$VM, getMethods, memoBox, $DOM, nextTick}) => ({
      plus : function(){
 
        const cnt = $VM('count');
 
        cnt.val( cnt.now()+1 );
      },
      minus : function(){
 
        const cnt = $VM('count');
 
        cnt.val( cnt.now()-1 );
      },
    }),
    data : {
      count: 0,
    },
  });
 
  return (<>{MVVMComponent}</>);
};
 
 
const root = ReactDOM.createRoot(document.getElementById('app'));
root.render(<React.StrictMode>
    <App />
</React.StrictMode>);

Bug Report

If you discover a bug or security vulnerability, please report it by opening an issue or contacting us directly.
Your help in improving this project is greatly appreciated!

If possible, please include a detailed description of the error along with screenshots or screen recordings. It would also be very helpful if you can provide a reproducible example using CodePen, JSFiddle, JSBin, or similar tools. Thank you.

Email

X(Twitter)

No other contact methods are available apart from those listed above.

Change Log

CHANGELOG.md

License

This project is partially open-source. It is free to use and can be used for commercial purposes.

For more details, please refer to the licensing terms below.

Apache 2.0 (check this out)

If you find this package helpful in your React projects,

please consider supporting it by making a donation Buy Me a Coffee at ko-fi.com or giving it a star ⭐️.

Your support helps keep the project going. Thank you!

About

import { useRespectVue } from '@gratefuljs/react-mvvm-component'; // React MVVM Component

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published