Skip to content

v0.5.3 - August 10

Choose a tag to compare

@krispya krispya released this 26 Nov 19:50
· 119 commits to main since this release

There are a few fixes here which includes making cached queries work with world.reset() and hardening the add/remove APIs when passing in multiple args. Two new hooks were also added.

useTag returns a boolean while useTrait returns a value. This is likely not what you want when using a tag in a hook.

const IsActive = trait()

function ActiveIndicator({ entity }) {
  // Returns true if the entity has the tag, false otherwise
  const isActive = useTag(entity, IsActive)

  if (!isActive) return null

  return <div>🟢 Active</div>
}

While tags are the usual need for a boolean return, you can more generically get this for any trait with the useHas hook.

const Health = trait({ amount: 100 })

function HealthIndicator({ entity }) {
  // Returns true if the entity has the trait, false otherwise
  const hasHealth = useHas(entity, Health)

  if (!hasHealth) return null

  return <div>❤️ Has Health</div>
}

What's Changed

Features
• feat: Add useTag by @krispya#176
• feat: Add useHas by @krispya#177

Fixes
• fix: Trait add and remove would early exit with variadic args by @krispya#167
• fix: Improve symbol resolution for $internal by @krispya#171
• fix: Cached queries empty after world reset by @jerzakm#172
• fix: Wildcard relations were removed early by @krispya#175

Chores
• chore: Rename TraitInstance to TraitRecord by @krispya#160
• chore: Update to new unplugin for inline plugin by @krispya#174

Docs
• docs: Fix typo in readme file by @borghiste#158
• docs: Fix typo (useStore → useStores) by @jerzakm#173

New Contributors

Full Changelog: v0.5.1...v0.5.3