[英]Recompose passing prop of an array of react elements
我開始使用 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;
看起來我不得不將 mapOptions 作為文字調用,因為它被分配給了一個變量。 還有一個問題是類型道具沒有作為 React.Node 的選項
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.