这实际上是关于React或React Native中的使用类型的文档。
我发现render()
function中的元素类型为React$Element<any>
。所以我在我的代码中尝试这个:
// @flow
import React from 'react';
import { Text } from 'react-native';
function greetingTextNode(string: string): React$Element<any> {
return (
<Text>Greeting, { string }.</Text>
)
}
但它在控制台中显示了一个flowtype错误:
20: <Text>Greeting, { string }.</Text>
^^^^^^ Text. This type is incompatible with
97: type _ReactClass<DefaultProps, Props, Config: $Diff<Props, DefaultProps>, C: React$Component<DefaultProps, Props, any>> = Class<C>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ React$Component. See lib: /private/tmp/flow/flowlib_243350bf/react.js:97
如何更正反应元素的流动类型?
答案 0 :(得分:-1)
尝试:
function greetingTextNode(str: string): React.Element<*> {
return (
<Text>Greeting, { str }.</Text>
)
}
你有正确的概念,只是没有正确的语法