I'm diving into ramdajs and refactoring some react code here. It might not necessary to do it in this case but for the sake of exercise how do I pass props in R.ifElse ?
{!this.state.repos ? <Loader /> : <RepoGrid repos={this.state.repos} />}
// refactoring to:
{R.ifElse(
R.isEmpty,
R.always(Loader),
RepoGrid
)(this.state.repos)}
This gives me an error Cannot read property '@@transducer/step' of null
const ReposGrid = R.pipe(
R.tap(console.log)
R.prop("repos"),
R.map(Repo),
ReposWraper
)
I'm not quite sure what it is you're looking for, but it sounds as though you want something like this:
const ReposGrid = repos => `| ${repos.join(' | ')} |`;
const Loader = `Loader`
const transform = R.ifElse(
R.isEmpty,
R.always(Loader),
ReposGrid
)
console.log(transform([]))
//=> 'Loader'
console.log(transform(['foo', 'bar', 'baz']))
//=> '| foo | bar | baz |'
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>
The arguments supplied to the function returned by ifElse
are supplied to the condition, consequent, and alternative functions. If this isn't what you want, what do you mean by passing identity to ReposGrid
? Should it actually be supplied the identity function? (e.g. (x) => x
?