【问题标题】:Recompose passing prop of an array of react elements重构一组反应元素的传递道具
【发布时间】:2018-08-03 01:32:54
【问题描述】:

我开始使用 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;

【问题讨论】:

    标签: reactjs flowtype recompose


    【解决方案1】:

    看起来我不得不将 mapOptions 作为文字调用,因为它被分配给了一个变量。还有一个问题是 type props 没有作为 React.Node 的选项

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 2019-05-26
      • 2016-12-11
      • 1970-01-01
      • 2019-07-29
      • 2017-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多