我开始使用重构库,效果很好。但是我有一些问题传递了反应元素的默认道具。
flow error:调用mapOptions函数不能在数组类型上调用
/* @flow */
import Input, { InputLabel } from 'material-ui/Input';
import Select from 'material-ui/Select';
import * as React from 'react';
import {withHandlers, withState, defaultProps, compose, withProps, mapProps} from 'recompose';
import { FormControl, FormHelperText } from 'material-ui/Form';
import {terms} from './Data/index'
import type { HOC } from 'recompose'
type Props ={
// options: Array<React.Element<string>>,
}
const mapOptions = Object.keys(terms).map(key=>
<option value={key}>{terms[key]}</option>
)
const BaseComponent = ({options})=>
<FormControl>
<InputLabel htmlFor="terms">Terms and Interest Rate</InputLabel>
<Select
native>
{options}
</Select>
</FormControl>
const TermComponent: HOC<*, Props> = compose(
defaultProps({
options: mapOptions()
})
)(BaseComponent)
export default TermComponent;
答案 0 :(得分:1)
看起来我必须将mapOptions称为文字,因为它已分配给变量。类型道具也没有选项作为React.Node
也存在问题