javascript - 反应自定义组件未呈现
问题描述
*自定义组件未在 UI 上呈现,还请注意,我有 id 元素:root
function CComponent(prop) {
const element = (
<div className="container">
<div className={prop.classname}>{prop.content}</div>
</div>
);
return element;
}
const helloElement = (
<CComponent>{{ classname: "xyz", content: "helloWorld" }}</CComponent>
);
console.log(helloElement);
ReactDOM.render(helloElement, document.getElementById("root"));
解决方案
您需要像这样将道具传递给组件:
const helloElement = <CComponent classname='xyz' content='helloWorld' />
推荐阅读
- javascript - React Native (Expo) - 默认情况下在 Android 上的键盘上推屏幕
- react-native - setState 挂钩未更新 - 尽管 prevState 显示正确的值
- object - 如何解决未定义对象的 TypeError
- c# - 从 C# 表单中搜索两个访问表
- firebase - 单独使用 Google Identity Platform + Firebase Auth
- javascript - 有没有办法在 firefox 扩展和 node.js 程序之间发送数据?
- laravel - Laravel 8 Multi Auth with Jetstream livewire
- sql - 使用空值加入和最大日期
- amazon-web-services - AWS 无服务器图像处理程序错误处理
- javascript - 展开所有文本区域,无需单击每个区域