我有这个条件;
branch(R.propSatisfies(R.isEmpty, "repos"), renderComponent(Loader)),
// branch(R.isEmpty("repos"), renderComponent(Loader)),
有什么区别以及为什么第二个给我一个错误? 测试不是函数
与此相同的结果:
branch(R.isEmpty(R.props("repos")), renderComponent(Loader)),
最佳答案
这是因为 R.propSatisfies
具有与 R.isEmpty
不同的方法签名。
对于您的第一种方法:
branch(R.propSatisfies(R.isEmpty, "repos"), renderComponent(Loader))
R.propSatisfies
函数正在对输入对象的属性 ("repos"
) 求值函数 (R.isEmpty
) (即从 renderComponent(Loader)
返回的对象)。
对于第二种方法:
// branch(R.isEmpty("repos"), renderComponent(Loader)),
您在这里所做的是直接调用R.isEmpty
。 R.isEmpty 方法需要一个数组,如果提供的数组为空,则返回 true。 R.isEmpty
无法确定对象中的属性(即“repos”)是否为空。为了更容易地直观地了解这里发生的情况,请考虑以下事项:
// Your second approach:
branch(R.isEmpty("repos"), renderComponent(Loader))
// ...which when expanded, is equivalent to this. You can now see it
// shows incorrect usage of R.isEmpty
branch(component => R.isEmpty("repos")(component), renderComponent(Loader))
希望这能提供一些澄清 - 有关 R.isEmpty
的更多信息,see this link
关于reactjs - 为什么这不适用于 recompose 和 ramda?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52175389/