📅  最后修改于: 2023-12-03 15:29:24.760000             🧑  作者: Mango
Anthesis is a lightweight JavaScript library for building reactive UI components. It provides a simple and intuitive API for building high-performance, reactive, and composable user interfaces.
Anthesis can be used either as a standalone library or as a plugin for a bigger framework.
To use Anthesis as a standalone library, simply include the latest version from a CDN:
<script src="https://unpkg.com/anthesis@latest/dist/anthesis.min.js"></script>
Then define your UI component using the anthesis
function:
const { anthesis, useState } = Anthesis;
const Counter = () => {
const [count, setCount] = useState(0);
return (
<div>
<h1>Counter</h1>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
);
};
anthesis(Counter, document.getElementById('app'));
To use Anthesis as a plugin for a bigger framework, simply import it as a module:
import Anthesis from 'anthesis';
const { useState } = Anthesis;
const Counter = () => {
const [count, setCount] = useState(0);
return (
<div>
<h1>Counter</h1>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
);
};
export default Counter;
Then use it in your framework of choice:
import Counter from './Counter';
// React
const App = () => <Counter />;
// Vue
const App = {
components: {
Counter
},
template: '<counter />'
};
Anthesis is a powerful and flexible library for building reactive UI components. Its simplicity and ease of use make it a great choice for smaller projects, while its composable architecture makes it ideal for larger and more complex applications. Try it out today and see how it can improve your workflow and performance!