miaoda-game-stats-react
v0.3.2
Published
React bindings for individual miaoda-game-stats-core values and stat sheets.
Readme
miaoda-game-stats-react
Use this React adapter to subscribe a component to one stat value without re-rendering for unrelated stats. It accepts either a standalone Stat or a named entry in a StatSet.
Install and use
pnpm add miaoda-game-stats-core miaoda-game-stats-reactimport { useStatValue } from 'miaoda-game-stats-react';
function HealthBar({ stats }: { stats: StatSet }) {
const hp = useStatValue(stats, 'hp');
const maxHp = useStatValue(stats, 'maxHp');
return <meter min={0} max={maxHp} value={hp} />;
}For a standalone derived value:
const attack = useStatValue(attackStat);React observes committed stat changes. Apply buffs, advance tick(dt), save, and decide gameplay rules in the core or engine/controller layer, not during render. Unknown named stats follow core behavior and throw, so define the sheet before mounting the view.
