Component Helpers
These are a collection of useful helper functions that will make development easier.
import {...} from 'two-way-rest
mapIf
arguments: (possibleIterator, mapFunction, noInteration*)
example:
mapIf(children, child=>child.get('name'), <div>No Children Exist</div> )
customAction
arguments: (args, customFn)
content: This function can be used during the actioncycle to perform a custom action on the state
example:
<TWRCreate tree='users' callforward={args=>
customAction(args, state=>state.delete('dogs'))
return args
}/>
createErrors
arguments: (instance from create, update, or destroy)
content: This function will output the errors in an instance using standard bootstrap tags
example:
<TWRCreate noErrors tree='users'>
<CreateUser />
</TWRCreate>
}/>
function CreateUser(props){
return <div>
<input type='text' name='name' />
{createErrors(props.instance)}
<button>Submit</buttom
}
==> If an error is thrown
<div className='default-errors'>
<span className='label label-danger'>Error</span>
<div>