BearStudio / formiz

🐜 React forms with ease! Composable, headless & with built-in multi steps
https://formiz-react.com/
MIT License
390 stars 50 forks source link

FEAT: maxLength/minLength options on useCollection #206

Open HugoPerard opened 10 months ago

HugoPerard commented 10 months ago

Is your feature request related to a problem? Please describe. This feature can avoid to manually do some check if we want to build a collection with some length condition, for example with at least one element, or/and with 10 elements max

const collection = useCollection("collection");
...
{collection.length > 1 && <button>Remove item</button>
...
{collection.length < 10 && <button>Add item<button>}

Describe the solution you'd like I'm thinking about two new states on the collection, with no name defined, that should transform previous to this :

const collection = useCollection("collection", { maxLength: 10, minLength: 1 });
...
{collection.canRemove && <button>Remove item</button>}
...
{collection.canAdd && <button>Add item</button>}