我在scala-js中为react-native编写包装器
lazy val reactNative = js.Dynamic.global.require("react-native")
val View = reactNative.View
val component = ReactNativeB[Unit]("NativeYeah")
.render(P => {
reactNative.createElement(View,null)
}).buildU
reactNative.AppRegistry.registerComponent("iOSscala", () => component())
组件注册良好,但是在创建View元素时失败!
null is not a function (evaluating ‘autoGenerateWrapperClass(tag)’)”
全栈跟踪:
CTJSLog> "Error:
stack:
getComponentClassForElement index.ios.bundle:5894
validatePropTypes index.ios.bundle:5634
createElement index.ios.bundle:5681
renderApplication index.ios.bundle:33913
run index.ios.bundle:33858
runApplication index.ios.bundle:33880
jsCall index.ios.bundle:7237
_callFunction index.ios.bundle:7484
applyWithGuard index.ios.bundle:877
guardReturn index.ios.bundle:7286
callFunctionReturnFlushedQueue index.ios.bundle:7493
URL: http://localhost:8081/index.ios.bundle
line: 5894
message: null is not a function (evaluating 'autoGenerateWrapperClass(tag)')"
在调试此功能时
function getComponentClassForElement(element) {
if (typeof element.type === 'function') {
return element.type;
}
var tag = element.type;
var componentClass = tagToComponentClass[tag];
if (componentClass == null) {
tagToComponentClass[tag] = componentClass = autoGenerateWrapperClass(tag);
}
return componentClass;
}
标签值是ReactElement
注意:上面的代码在带有div标签/ react组件的reactjs中可以正常工作.
编辑:它的问题来自scalajs-react生成器,它遵循ReactJS渲染API而不是AppRegistry,关闭问题.
解决方法:
如果您要渲染的组件未定义(as per this issue),您将看到此错误消息.在将组件传递给registerComponent之前,component的值是多少?