我创建了组件(完全100%工作)并在将其移动到新目录后,在点击了react-select上的选择组件(应列出所有选项但崩溃)之后,我是得到:
manage-pois.js?v=1523440002:34563 Uncaught TypeError: Cannot read property 'offsetTop' of null
at Select.componentDidUpdate (manage-pois.js?v=1523440002:34563)
at commitLifeCycles (manage-pois.js?v=1523440002:16708)
at commitAllLifeCycles (manage-pois.js?v=1523440002:17876)
at HTMLUnknownElement.callCallback (manage-pois.js?v=1523440002:8472)
at Object.invokeGuardedCallbackDev (manage-pois.js?v=1523440002:8511)
at invokeGuardedCallback (manage-pois.js?v=1523440002:8368)
at commitRoot (manage-pois.js?v=1523440002:17980)
at performWorkOnRoot (manage-pois.js?v=1523440002:18947)
at performWork (manage-pois.js?v=1523440002:18897)
at batchedUpdates (manage-pois.js?v=1523440002:19016)
这是我的代码,我正在渲染选择字段:
renderSelectCountry() {
const {countries} = this.state;
let options = countries ? countries.map((country) => {
return {value: country.id, label: country.title};
}) : [];
return <Select
value={this.state.countryId}
placeholder='Country*'
onChange={(e) => {
this.setState({countryId: e ? e.value : ''})
}}
options={options}
style={{marginBottom: '0px'}}
/>
}
答案 0 :(得分:0)
<Select>
组件尝试从表示所选选项的DOM元素中获取offsetTop
属性。似乎由于某种原因,该选项没有安装DOM节点。
我使用您的代码创建了一个minimal codesandbox example,它似乎有效。
问题可能不在您提供的代码中。