You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/publish/README.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -913,6 +913,40 @@ return (
913
913
)
914
914
```
915
915
916
+
### `useTag`
917
+
918
+
Observes an entity, or world, for a tag and reactively updates when it is added or removed. Returns `true` when the tag is present or `false` when absent. Use this instead of `useTrait` for tags. For tracking the presence of non-tag traits, use `useHas`.
919
+
920
+
```js
921
+
constIsActive=trait()
922
+
923
+
functionActiveIndicator({ entity }) {
924
+
// Returns true if the entity has the tag, false otherwise
925
+
constisActive=useTag(entity, IsActive)
926
+
927
+
if (!isActive) returnnull
928
+
929
+
return<div>🟢 Active</div>
930
+
}
931
+
```
932
+
933
+
### `useHas`
934
+
935
+
Observes an entity, or world, for any trait and reactively updates when it is added or removed. Returns `true` when the trait is present or `false` when absent. Unlike `useTrait`, this only tracks presence and not the trait's value.
936
+
937
+
```js
938
+
constHealth=trait({ amount:100 })
939
+
940
+
functionHealthIndicator({ entity }) {
941
+
// Returns true if the entity has the trait, false otherwise
942
+
consthasHealth=useHas(entity, Health)
943
+
944
+
if (!hasHealth) returnnull
945
+
946
+
return<div>❤️ Has Health</div>
947
+
}
948
+
```
949
+
916
950
### `useTraitEffect`
917
951
918
952
Subscribes a callback to a trait on an entity. This callback fires as an effect whenever it is added, removed or changes value without rerendering.
0 commit comments