我有一個返回JSX一個函數,如下所示:陣營分量函數返回應用於渲染ES6類的方法時JSX導致錯誤發生反應組分
function struct(locals) {
return (
<View style={fieldsetStyle}>
{label}
{error}
{rows}
</View>
);
}
label, error, and rows are functions that also return JSX.
我調用ES6類的呈現方法中的這個功能組件
class Component extends React.Component {
render() {
const locals = this.getLocals();
return struct(locals);
}
}
當我運行代碼,我得到錯誤
元素類型無效:預期字符串(內置組件)或 類/函數(用於複合組件)但是得到了:object。檢查渲染 方法Struct
如何從結構函數中獲取結果以呈現組件類的渲染返回值?
您是否有充分的理由將此作爲單獨的功能?爲什麼你不把它變成一個'LocalsView'組件並且把它作爲prop來傳遞'locals'? –