Ant Design报Cannot use 'in' operator to search for 'value' in undefined错误的一种情形

报错的地方,是用在getFieldDecorator中,Ant Design版本2.9.0,大致jsx代码如下:

let labelOption = ();

    
        {getFieldDecorator('label')(
            {labelOption}
        )}
    

前端启动之后,报如题错误:

TypeError: Cannot use 'in' operator to search for 'value' in undefined
    at eval (createBaseForm.js:175)
    at DealerAccessNotPassList.render (dealerAccessNotPassList.jsx:331)
    at eval (ReactCompositeComponent.js:796)
    at measureLifeCyclePerf (ReactCompositeComponent.js:75)
    at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js:795)
    at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js:822)
    at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js:746)
    at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js:724)
    at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js:645)
    at ReactCompositeComponentWrapper.performUpdateIfNecessary (ReactCompositeComponent.js:561)

修改为:


    
        {getFieldDecorator('label')(
            
{labelOption}
)}

不会再报上述错误,但是getFieldDecorator拿不到form中label的值。

无奈,只得在Select组件的onChange中给form中的label赋值,如下:

handleLabelChange =(value)=> {
     console.log(`selected ${value}`);
    this.props.form.setFieldsValue({label:value});
 }

 

你可能感兴趣的:(Ant,Design)