我如何 return 一个通过 R.ifElse 传递道具的组件?
How do I return a component with passed props with R.ifElse?
我正在研究 ramdajs 并在这里重构一些反应代码。在这种情况下可能没有必要这样做,但为了练习,我如何在 R.ifElse 中传递道具?
{!this.state.repos ? <Loader /> : <RepoGrid repos={this.state.repos} />}
// refactoring to:
{R.ifElse(
R.isEmpty,
R.always(Loader),
RepoGrid
)(this.state.repos)}
这给我一个错误Cannot read property '@@transducer/step' of null
const ReposGrid = R.pipe(
R.tap(console.log)
R.prop("repos"),
R.map(Repo),
ReposWraper
)
我不太确定你在找什么,但听起来你想要这样的东西:
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>
提供给 ifElse
返回的函数的参数被提供给条件、结果和替代函数。如果这不是您想要的,将身份传递给 ReposGrid
是什么意思?它实际上应该提供身份功能吗? (例如 (x) => x
?
我正在研究 ramdajs 并在这里重构一些反应代码。在这种情况下可能没有必要这样做,但为了练习,我如何在 R.ifElse 中传递道具?
{!this.state.repos ? <Loader /> : <RepoGrid repos={this.state.repos} />}
// refactoring to:
{R.ifElse(
R.isEmpty,
R.always(Loader),
RepoGrid
)(this.state.repos)}
这给我一个错误Cannot read property '@@transducer/step' of null
const ReposGrid = R.pipe(
R.tap(console.log)
R.prop("repos"),
R.map(Repo),
ReposWraper
)
我不太确定你在找什么,但听起来你想要这样的东西:
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>
提供给 ifElse
返回的函数的参数被提供给条件、结果和替代函数。如果这不是您想要的,将身份传递给 ReposGrid
是什么意思?它实际上应该提供身份功能吗? (例如 (x) => x
?