Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@bramblex/state-model-react
Advanced tools
为 React 设计的简易模型,帮助 React 用户进行模型驱动设计。
使用 npm 安装
npm install --save @bramblex/state-model
使用 yarn 安装
yarn add @bramblex/state-model
import {
StateModel,
useModel,
useLocalModel,
useModelProvider,
useModelContext
} from '@brambles/state-model'
class Counter extends StateModel<{ count: number }> {
constructor() {
super({ count: 0 })
}
increase() {
this.setState({ count: this.state.count + 1 });
}
decrease() {
this.setState({ count: this.state.count - 1 });
}
}
const counter = new Counter();
function App() {
useModel(counter);
return (
<div>
<div>{model.state.count}</div>
<div>
<button onClick={() => counter.increase()}>+</button>
<button onClick={() => counter.decrease()}>-</button>
</div>
</div>
);
}
function App() {
const counter = useLocalModel(() => new Counter(), []);
return (
<div>
<div>{model.state.count}</div>
<div>
<button onClick={() => counter.increase()}>+</button>
<button onClick={() => counter.decrease()}>-</button>
</div>
</div>
);
}
function Increase() {
const counter = useModelContext(Counter);
return <button onClick={() => counter.increase()}>+</button>
}
function Decrease() {
const counter = useModelContext(Counter);
return <button onClick={() => counter.decrease()}>-</button>
}
function Count() {
const counter = useModelContext(Counter);
useModel(counter);
return <div>{model.state.count}</div>
}
function App() {
const counter = useLocalModel(() => new Counter(), []);
// 等效于
// const counter = useModel(useMemo(() => new Counter(), []));
const Provider = useModelProvider(Counter);
return (
<Provider value={counter}>
<div>
<Count />
<div>
<Increase />
<Decrease />
</div>
</div>
</Provider>
);
}
FAQs
Simple model
The npm package @bramblex/state-model-react receives a total of 6 weekly downloads. As such, @bramblex/state-model-react popularity was classified as not popular.
We found that @bramblex/state-model-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.