Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 1.1 KB

README.md

File metadata and controls

53 lines (39 loc) · 1.1 KB

🪝 useTagged

function useTagged<T extends Instance>(tag: string): readonly T[];

Tracks and returns all instances assigned to the given CollectionService tag. Re-renders the component when tagged instances are added or removed from the data model.

📕 Parameters

  • tag - The tag to filter instances for.

📗 Returns

  • A list of instances with the given tag.

📘 Example

Get all instances with the tag "Zombie":

function ZombieHealth() {
	const zombies = useTagged("Zombie");

	return (
		<>
			{zombies.map((zombie) => (
				<ZombieHealthbar model={zombie} />
			))}
		</>
	);
}

Get all instances with the tag "Zombie" and cast them to a custom ZombieModel type:

interface ZombieModel extends Model {
	Health: NumberValue;
}

function ZombieHealth() {
	const zombies = useTagged<ZombieModel>("Zombie");

	return (
		<>
			{zombies.map((zombie) => (
				<ZombieHealthbar model={zombie} />
			))}
		</>
	);
}