我开始使用 recompose 库,效果很好。但是我在传递反应元素的默认道具时遇到了一些问题。
流错误:不能在数组类型上调用 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;