2
我有這個問題,我試着用反應呈現HTMLDivElement,但是我得到以下錯誤:渲染HTMLDivElement在陣營
Uncaught Invariant Violation: Objects are not valid as a React child (found: [object HTMLDivElement]). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `VirtualList`
在我的陣營組件類我有這樣的代碼...
import React, { Component } from 'react';
export default class VirtualList extends Component {
constructor(props) {
super(props);
this.container = document.createElement('div');
}
renderList() {
let container = this.container;
// Manipulate container etc.
return container;
}
render() {
return (
<div>
{this.renderList()}
</div>
)
}
}
幫助將不勝感激!
請問您爲什麼要使用'document.createElement'? –
這不是對付dom的反應方式。 –
@AlexanderT。我編寫了一些帶有一些邏輯的普通JavaScript代碼,因此我想從某種意義上說,將代碼移植到React中,並認爲您可以呈現HTMLDivElement對象 – slim1801