@wazapp/helpers
Helpers are utils that are meant to be used mostly in component templates.
API
each(collection, onItem, onEmpty)
each
will make your iterations in template a breeze. It takes care of unique keys for each element, as well as simplify the syntax.
It takes 3 arguments:
collection
- an array of somethingonItem(item, index)
- callback which will be used for each item in the collectiononEmpty
-optional
-ReactNode
that will be returned in case the collection is empty.
Example
Before
After
when(condition, ifTrue, ifFalse)
when
is simple if
statement which does not require to return null
as false case.
It takes 3 arguments:
condition
ifTrue
- value when trueifFalse
- value when false
Example
Before
After
classNames()
Exposes: https://github.com/JedWatson/classnames
yieldChildren(children, ...args)
yieldChildren
allows you to return component's children
or in case the children
is a function, it will allow you to call it with custom arguments.
Arguments:
children
:ReactNode | Function
...args
:any[]
- your custom arguments that will be used onchildren
call (ifchildren
is a function)
Last updated
Was this helpful?