clear()

The clear() method removes all items from your collection, regardless of the initial state. This is useful when you need to empty the collection completely.

import { createCollection } from 'finalstore';
 
const users = createCollection({
  states: {
    name: '',
    age: 0,
    active: true
  },
  actions: {
    updateName: (state, name: string) => {
      state.name = name;
    }
  }
});
 
function ClearButton() {
  const size = users.useSize();
 
  return (
    <div>
      <p>Current Users: {size}</p>
      <button
        onClick={() => {
          users.clear();
          console.log('Collection cleared:', users.getSize()); // Output: 0
        }}
      >
        Clear All Users
      </button>
    </div>
  );
}