【发布时间】:2021-03-28 18:23:12
【问题描述】:
错误是: 对象作为 React 子对象无效(找到:带有键 {code、message、a} 的对象)。如果您打算渲染一组子项,请改用数组。
我将在我尝试渲染组件的位置显示我的代码:
document.querySelector(".App").innerHTML = "";
const errorElement = <ShowErr message={err} />;
ReactDOM.render(errorElement, document.querySelector(".App"));
我的组件:
import Button from "@material-ui/core/Button";
const reload = () => {
window.reload();
};
const ShowErr = (props) => {
const imgStyle = {
display: "block",
margin: "auto",
marginTop: "100px",
marginBottom: "50px",
borderRadius: "50%",
};
const msgStyle = {
textAlign: "center",
marginTop: "30px",
fontFamily: "Ubuntu",
color: "red",
};
const btnStyle = {
display: "block",
margin: "auto",
marginTop: "50px",
};
return (
<div className="err">
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@300&display=swap"
rel="stylesheet"
></link>
<img
src="https://img.icons8.com/emoji/48/000000/cross-mark-button-emoji.png"
style={imgStyle}
/>
<h3 className="error-msg" style={msgStyle}>
{props.message}
</h3>
<Button color="secondary" style={btnStyle} onClick={reload}>
Reload and Try Again
</Button>
</div>
);
};
export default ShowErr;
如果有解决办法请告知
【问题讨论】:
标签: javascript reactjs firebase web react-component