[英]Uncaught TypeError: Cannot read property 'offsetTop' of null
[英]React-select: Uncaught TypeError: Cannot read property 'offsetTop' of null
我已經創建了組件(完全 100% 工作)並將其移動到新目錄后,在從react-select單擊 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)
這是我渲染 Select 字段的代碼:
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'}}
/>
}
<Select>
組件嘗試從代表所選選項的DOM元素獲取offsetTop
屬性。 似乎由於某種原因該選項未安裝DOM節點。
我用您的代碼創建了一個最小的codesandbox示例 ,它似乎可以工作。
您提供的代碼中可能沒有此問題。
我發現了問題。 您可能從react-select-2
安裝並導入Select
。 但是你應該使用react-select
(沒有-2
)。
我有同樣的問題。 使用react-select
使一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.